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

If the bus travels with 8 tyres(6 tyres running),travels a distance of 16000 km how much is the distance sustained by each tyre.

1911


The area of the maximum size of the circle described from the 10 square inch square?

934


There's a camel living in a desert. There is a market 1000 miles away. The camel has 3000 dates for sale. It has to take the date to the market. But for that hte camel eats one date per mile. How many dates the camel can trade?

828


A man collects cigarette stubs and makes one full cigarette with every 8 stubs.If he gets 64 stubs how many full cigarettes can he smoke.

1305


The ratio between two numbers is 5:7 and their product is 560. What is the difference between these two numbers?

1324






Distance d=rt where r & t are positive and r is constant,as t increases then d_________

743


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?

732


A power unit is there by the bank of the river of 750 meters width. A cable is made from power unit to power a plant opposite to that of the river and 1500mts away from the power unit. The cost of the cable below water is Rs. 15/- per meter and cost of cable on the bank is Rs.12/- per meter. Find the total of laying the cable.

843


a man has some hens and cows. If the number of heads be 48 and the number of feet equals 140, then the number of hens will be?

788


Radha, Geeta & Revathi went for a picnic.After a few days they forgot the date,day and month on which they went to picnic.Radha said that it was on Thursday,May 8 and Geeta said that it was Thursday May 10.Revathi said Friday June 8.Now one of them told all things wrongly,others one thing wrong and the last two things wrongly.If April 1st is tuesday what is the right day,date and month?

785


A sales person multiplied a number and get the answer is 3, instead of that number divided by 3. what is th answer he actually has to get ?

767


A man drives at a speed of 40 miles/hr. His wife left 30 mins. late with 50 miles/hr speed. when will they meet ?

1224


For a 13-bit DAC the MSB resistance is 2kohms. What is the LSB resistance ?

1033


In a class composed of x girls and y boys what part of the class is composed of girls

826


Two distinct no's are taken from 1,2,3,4......28. Find the probability that their sum is less than 13

900