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
the minimum of (2x+1)**2 + (x+2) is at x =
a man purchased 6 stamps of rupees 1 and seven stamps of 50 paise.he paid Rs. 12. how much change he got back ?
In a queue, a man is standing at the position 10th from the front and 15th from behind. How many persons are standing in the queue?
a vendor solds two things at same cost 12 RS with one item at 25%profit and other at 20%loss,by this transaction he made profit or loss by how much
A printer produced 176,400 pages in a given day. If the printer was in operation for seven hours during the day, how many pages did it print per minute?
hai am Deepak here i have my exam on 3rd jan 2010 for the post of officers job in karnataka bank so kindly plz send me model papers . thank u
if x/y =4 and y is not '0' what % of 'x' is '2x-y'
A and b can do a piece of work in 15 and 10 days. A and b work on it for sometime and then a leaves b completes the job in 5 days. For how long did a work.
Ram spends half of his salary on household expenses, quarter for rent, 1/5th for medical expenses and the remaining he deposits in the bank. If his monthly deposits in the bank is Rs 50, what is his monthly salary ?
A finishes the work in 10 days & B in 8 days individually. If A works for only 6 days then how many days should B work to complete A's work?
500 men are arranged in an array of 10 rows and 50 columns . ALL tallest among each row aare asked to fall out . And the shortest among THEM is A. Similarly after resuming that to their originaal podsitions that the shorteest among each column are asked to fall out. And the longest among them is B . Now who is taller among A and B ?
the probability of getting at least in a single through of three coins is
There N stations on a railroad. After adding x stations 46 additional tickets have to be printed. Find N and X.
Find the next letter in the series A,C,F,J,0--
A&B fill 3 litres and 5 litres of oil in the car. C pays Rs. 8/- to A7B. How much will A get?