Wipro - C & C++ Coding Ability

Test Number 14


You are given an integer N. Your task is to print the number in reverse order. 

INPUT:
The first line contains an integer T, the total number of test cases. 

Then follow T lines, each line contains an integer N.



OUTPUT:
For each test case, display the reverse of the given number N, in a new line.



Test Case: 1

INPUT:
2 

3456

8796



OUTPUT:
6543

6978

                

#include < stdio.h>

int main(void)

{

	int T;

	scanf("%d",&T);

	

	while(T--)

	{

	  int A,rem,rev=0;

	  scanf("%d",&A);

	  while(A!=0)

	  {

	       rem = A%10;

	       rev = rev*10+rem;

	       A=A/10;

	  }

	  printf("%d\n",rev);

	}

	return 0;

}               






You are given with an array A of size N, print the reverse of it.

Input:
First line of input contains an integer denoting the test cases 'T'. 

Each testcase contains two lines of input. 

First line contains N the size of the array A. 

The second line contains the elements of the array.

Output:
For each testcase, in a new line, print the array in reverse order.                   

#include< iostream>

#include < algorithm>

using namespace std;

int main()

 {

	int T;

	cin >>T;

	int arr[100];

	while (T--)

	{

	   int n;

	   cin >>n;

	   for (int i=0; i< n; i++)

	   {

	       cin >> arr[i];

	   }

	   for (int i=n-1; i>=0; i--)

	   {

	       cout << arr[i] << " ";

	   }

	   cout<< endl;

	}

	return 0;

}                   






You are given an unsorted array arr[ ] of size N, rotate it by D elements (clockwise). 

Input:
The first line of the input contains T denoting the number of testcases.

 First line of each test case contains two space-separated elements, N denoting the size of the array and an integer D denoting the number size of the rotation. 

The next line will be the N space-separated elements of the array.

Output:
For each testcase, in a new line, output the final rotated array.


Test Case: 1

INPUT:
1

9 3

2 3 4 5 6 7 8 9 1



OUTPUT:

5 6 7 8 9 1 2 3 4                          

#include

using namespace std;

int main()

 {

	

	int T;

	cin >> T;

	while(T--)

	{

	    int N, D;

	    cin >> N >> D;

	    int arr[N];

	    for(int i=0; i< N; i++)

	    {

	        cin >> arr[i];

	    }

	    for(int i=D; i< N; i++)

	    {

	        cout << arr[i] <<" ";

	    }

	    for(int i=0; i< D; i++)

	    {

	        cout << arr[i] <<" ";

	    }

	    cout << endl;

	    

	}

	return 0;

}                          






You are given 3 positive integers A, B and C. Your task is to print the second largest element among them.

INPUT:
The first line contains an integer T, the total number of test cases.

 Then T lines follow, each line contains three integers A, B, and C.

OUTPUT:
For each test case, display the second largest among A, B and C, in a new line.



Example:

Test Case: 1

INPUT:

1

23 43 16

OUTPUT:
23

Explanation:

43 > 23 > 16

so the answer is 23

                     

#include < iostream>

using namespace std;



int main() {

    

	int T;

	cin >> T;

	while(T--)

	{

	    int a, b, c;

	    cin >> a >> b >> c;

	    if ((a>=b && b>=c) || ((c>b) && (b>a)))

	    {

	        cout << b << endl;

	    }

	    else if((b>=a && a>=c) || ((c>a) && (a>b)))

	    {

	        cout << a << endl;

	        

	    }

	    else 

	    {

	        cout << c << endl;

	    }

	        

	        

	        

	}

	return 0;

}

                             






You are given the values of the principal amount (P), the rate of interest (R), and the time period (T). Your task is to calculate the simple interest for the given principal amount.



INPUT:
The first line of input contains 3 space-separated float values denoting the values of P, R, and T respectively.  



OUTPUT:
Contains a float value indicating the value of Simple Interest.



Test Case: 1

INPUT:

100 10 5

OUTPUT:
50.000000

                    

#include< stdio.h>

#include

int main()

{

	float p,n,r,si;

	scanf("%f%f%f",&p,&n,&r);

	si=p*n*r/100;

	printf("%f",si);

}