Accept any two numbers from the user.
Perform the following operations on it using functions:
1. Addition
2. Subtraction
3. Multiplication
4. Swap the values
5. Print both the numbers in reverse order for example (if
a given number is 234, it should
be printed as 432)



Accept any two numbers from the user. Perform the following operations on it using functions: 1. A..

Answer / neeru bansal

/*Question 2 . Accept any two numbers from the user.
Perform the following operations on it using functions:
1. Addition
2. Subtraction
3. Multiplication
4. Swap the values
5. Print both the numbers in reverse order for example (if a
given number is 234, it should
be printed as 432)
CONCEPT : Using SWITCH statement and functions
SYNTAX : switch
{
case 1: statements;
Break;
case 2: statements;
Break;

default: statements;
}
*/

// Declaration for the preprocessor::
#include
#include
// Main function begins::
void main()
{
// Declaration of variables::
int a,b,c,t,n,num;
long int i;
int l;
char ch;
// Declaration of functions::
char num_status(int);
void sum(int,int);
void sub(int,int);
void mul(int,int);
void swap(int,int);
int reverse(int);
// To clear the screen before printing ::
clrscr();
// Printing SCDL student details for code-authentication::
printf(“\n***************************************\n NAME :
PRIYANKA”);
printf(“\n COURSE: PGDIT [1st Sem.]“);
printf(“\n REGISTRATION NUMBER: 200705826″);
printf(“\n SUBJECT: Assignment for C Programming
\n***************************************”);
// printing the directions for user to select::
printf(“\n\nPerform the following operations:\n”);
printf(“\n1.Addition:\n”);
printf(“\n2.Subtration:\n”);
printf(“\n3.Multiplication:\n”);
printf(“\n4.Swap the values:\n”);
printf(“\n5.Print the numbers in reverse order:”);
printf(“\n\nSlect your operation:\n”);
scanf(“%d”,&l);// accepts the operation choice
ch=num_status(l);// calling function for selectiong choice

//switch statement for the calculation
switch(ch)
{
case ’1′:
printf(“Enter the first number:\t”);
scanf(“%d”,&a);
printf(“Enter the second number:\t”);
scanf(“%d”,&b);
sum(a,b);
break;

case ’2′:
printf(“Enter the first number:\t”);
scanf(“%d”,&a);
printf(“Enter the second number:\t”);
scanf(“%d”,&b);
sub(a,b);
break;

case ’3′:
printf(“Enter the first number:\t”);
scanf(“%d”,&a);
printf(“Enter the second number:\t”);
scanf(“%d”,&b);
mul(a,b);
break;

case ’4′:
printf(“Enter the first number:\t”);
scanf(“%d”,&a);
printf(“Enter the second number:\t”);
scanf(“%d”,&b);
swap(a,b);
break;

case ’5′:
printf(“Enter the first number:\t”);
scanf(“%d”,&a);
printf(“The reverse of %d is %d”,a,reverse(a));
printf(“\nEnter the second number:\t”);
scanf(“%d”,&b);
printf(“The reverse of %d is %d”,b,reverse(b));
break;
}
getch();
}
// Function definition for selecting choice::
char num_status(int l)
{
if(l==1)
return ’1′;
else if(l==2)
return ’2′;
else if(l==3)
return ’3′;
else if(l==4)
return ’4′;

else
return ’5′;
}
// Function definition for addition of 2 numbers::
void sum(int a,int b)
{
int c;
c=a+b;
printf(“Addition of 2 numbers:\n a=%d\t b=%d\n c=%d\n”,a,b,c);
}
// Function definition for subtraction of 2 numbers::
void sub(int a,int b)
{
int c;
c=a-b;
printf(“Subtraction of 2 numbers:\n a=%d\t b=%d\n
c=%d\n”,a,b,c);
}
// Function definition for multiplication of 2 numbers::
void mul(int a,int b)
{
int c;
c=a*b;
printf(“Multiplication of 2 numbers:\n a=%d\n b=%d\n
c=%d\n\t\t “,a,b,c);
}
// Function definition for swapping of 2 numbers::
void swap(int a,int b)
{
int t;
t=a;
a=b;
b=t;
printf(“After swapping 2numbers:\n a=%d\n b=%d\n”,a,b,t);
}
// Function definition for reversing 2 numbers::
int reverse(int n)
{
int r,rev;
rev=0;
while(n!=0)
{
r=n%10;
n=n/10;
rev=rev*10+r;
}
return rev;
}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More General Aptitude Interview Questions

A, B ans C are three speakers. They have to speak randomly along with another 5 speakers in a function. A has to speak before B and B has to speak before C. What is the probability.

0 Answers   Flipkart,


Integral B(Transpose)*sigma(here sigma means stress)*dV REPRESENTS?

0 Answers  


Find the smallest number which leaves 22,35, 48 and 61 as remainders when divided by 26, 39, 52 and 65 respectively.

0 Answers   Accenture,


Hi frds, can any one send me previous soved question papers of SBI clerical post....my mail id is venky.lotus@gmail.com...Thanks in Advance

0 Answers  


Please send me the Karur Vysya Bank Clerk exam previous model papers to shekar96@gmail.com

14 Answers   Karur Vysya Bank KVB, KVB, L&T, Sugen, TCS,






There are two balls touching each other circumferencically. The radius of the big ball is 4 times the diameter of the small ball.The outer small ball rotates in anticlockwise direction circumferencically over the bigger one at the rate of 16 rev/sec. The bigger wheel also rotates anticlockwise at Nrev/sec. what is 'N' for the horizontal line from the centre of small wheel always is horizontal.

0 Answers   Infosys,


An orange glass has orange juice and white glass has apple juice both of equal volumes. 50ml of the orange juice is taken and poured into the apple juice. 50ml from the white glass is poured into the orange glass. Of the two quantities, the amount of apple juice in the orange glass and the amount of orange juice in the white glass, which one is greater and by how much?

0 Answers   Infosys,


which one of following group animals are primates

2 Answers   CDS,


In a pond ecosystem, large fishes and small fishes will be there. If we want to remove small amount of pollutants, small fishes are to be employed. In a food chain food passes through a number of mouths and en route the mouth of the super feeder-the eagle. Its population determines the size of the ecosystem. But this has been proved false.What can you infer from above? (4 choices)

0 Answers   Accenture,


Adam stands facing towards northwest direction.He walks 61 m and then turns southwards and walks another 60 m. How far is he from the starting point.?

0 Answers   Mecon,


A tailor has 37.5 metres of cloth and he has to make 8 piecesout of a metre of cloth. How many pieces can he make out of this cloth?

0 Answers  


3,10,20,27,54,61,?

11 Answers   Assurgent, Wafer Space,


Categories