Tech Mahindra 2nd April 2021 Asked in All 6 Shifts Complete Question Papers | Download All Section Aptitude, English Essay & Tech MCQ and Coding solution Complete in One PDF
Write a program to calculate the total bill tax amount for a list of billing amounts passed as an array of long integers. Up to the amount 1000, there is no tax applicable, subsequently, a flat tax of 10% is applicable for the remaining amount as per the tax rate.
Note:
All calculations and results should be integer-based ignoring fractions
You are expected to write code in the calcTotalTax function only which will receive the first parameter as the number of items in the array and the second parameter as the array itself. You are not required to take input from the console.
Example
Calculating total tax for a list of 5 billing amount
Input
5
1000 2000 3000 4000 5000
Output
1000
Explanation
The first parameter (5) is the size of the array. Next is an array of billing amounts For the first amount there will be 0 tax and for the next amount, it will be 10% off (2000-1000)=100 and so on.
The sum of all the tax amounts will be (0+100+200+300+400=1000)
Write a program to return the difference between the sum of odd and even numbers from an array of positive integers.
Note:
You are expected to write code in the findOddEvenDifference function only which will receive the first parameter as the number of items in the array and the second parameter is the array itself. You are not required to take input from the console
Example:
Finding the difference between the sum of odd even numbers from a list of 5 numbers
Write a program to find the maximum difference between two adjacent numbers in an array of positive integers.
Note:
You are expected to write code in the findMaxDifference function only which will receive the first parameter as the number of items in the array and the second parameter is the array itself. You are not required to take input from the console.
Example
Finding the maximum difference between adjacent items of a list of 5 numbers
Input
5
10 11 7 12 14
Output
4
Explanation
The first parameter (5) is the size of the array. Next is an array of integers. The difference between the integers 11 and 7 is 4 which is maximum compared to any other adjacent numbers in the list as follows:
10-11=-1
11-7=4
7-12=-5
12-14=-2
Code Solution in C++:
Input
5
10 11 7 12 14
#include<iostream>
using namespace std;
int findMaxDifference(int arr[],int n)
{
int max=-999999;
for(int i=0;i<n-1;i++)
if(arr[i]-arr[i+1]>max)
max=arr[i]-arr[i+1];
return max;
}
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
cout<<findMaxDifference(a,n);
return 0;
}
5. FindTotalFeet
Given an array of integers representing measurements in inches, write a program to calculate the total of measurements in feet. Ignore the measurements that are less than a feet (eg. 10).
Note:
You are expected to write code in the findTotalFeet function only which will receive the first parameter as the number of items in the array and the second parameter as the array itself. You are not required to take input from the console
Example:
Finding the total measurements in feet from a list of 5 numbers
Input
5
18 11 27 12 14
Output
5
Explanation
The first parameter (5) is the size of the array. Next is an array of measurements in inches.
The total number of feet is 5 which is calculated as shown below:
Stay tuned with www.freshersocjob.comto receive more such updates on recruitment. Join our Telegram Channel and Join our WhatsApp Group To get Instant updates for All Recruitment Internships and Off-Campus of 2021 Pass-Out Batch and Other Batch.
Don’t Miss any Job Opportunity, Follow us On Following Social Media & Get Instant Job Notifications on Mobile.
Comments
Post a Comment