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)

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

consider expression 'ab' . what happens when 'a' is divided by 'c' &'b' is multiplied by 'c'.

1096


Two trains move in the same direction at 50 kmph and 32 kmph respectively. A man in the slower train observes the 15 seconds elapse before the faster train completely passes by him. What is the length of faster train?

931


15 Men take 21 days of 8 hrs. each to do a piece of work. How many days of 6 hrs. each would do if 21 women take. If 3 women do as much work of 2 men.

1004


How many rational numbers are there between 0 & 5?

953


A person has Rs 100/- in his pocket, he can as 25 pencils or 15books. He kept 15% of the money for travelling expenses and purchased 5 ncils.So how many books he can purchase with the remaining money.

1042


One guy (some name) has Rs. 100/- in hand. He has to buy 100 balls. One football costs Rs. 15/, One Cricket ball costs Re. 1/- and one table tennis ball costs Rs. 0.25 He spend the whole Rs. 100/- to buy the balls. How many of each balls he bought?

1939


Let's say that you have 25 horses, and you want to pick the fastest 3 horses out of those 25. In each race, only 5 horses can run at the same time because there are only 5 tracks. What is the minimum number of races required to find the 3 fastest horses without using a stopwatch?

1069


What is degree of a Relation?

959


(Momentum*Velocity)/(Acceleration * distance ) find units.

920


Four persons can cross a bridge in 3, 7, 13, 17 minutes. Only two can cross at a time. Find the minimum time taken by the four to cross the bridge.

1076


A man drives at a speed of 40 miles/hr while his friend drives at a speed of 50 miles/hr. If the friend leaves 30 minutes after the man, when are they going to meet?

961


all apscsc question papers

2238


If x,y,z are chosen frm -3,1/2,2 what is the largest value of (x/y)*z*z

970


in a railway station, there are tow trains going. One in the harbour line and one in the main line, each having a frequency of 10 minutes. the main line service starts at 5 o'clock. the harbour line starts at 5.02a.m. a man goes to the station every day to catch the first train. what is the probability of man catchinhg the first train

933


Scientific publishing aptitude interview question

1241