Can someone urgently help me to write C program which
Accept any two numbers from the user. Perform the following operations on it using functions:
Addition
Subtraction
Multiplication
Swap the values
Print both the numbers in reverse order for example (if a given number is 234, it should be printed as 432)
- Riya
C Program Help (Urgent !!!)?
This program will do all the tasks that are mentioned by you.
1) Addition
2) Subtraction
3) Multiplication
4) Swapping
5) Reverse Order Printing of a number
#include%26lt;stdio.h%26gt;
int reverseIt( int num );
void main( ) {
int num1, num2, result, tmp;
printf( "Enter first number: " );
scanf( %26amp;num1 );
printf( "Enter 2nd number: " );
scanf( %26amp;num2 );
result = num1+num2;
printf( "\nSum is: %d\n", result );
result = num1-num2;
printf( "Subtraction of %d from %d is: %d\n", num2, num1, result );
result = num1*num2;
printf( "Mulitplication of these two numbers is: %d\n", result );
tmp = num1;
num1 = num2;
num2 = tmp;
printf( "Swaping the two numbers:\n\n" );
printf( "Number 1 is now: %d\n", num1 );
printf( "Number 2 is now: %d\n", num2 );
printf( "\nReverse of Number 1 is: %d\n", reverseIt( num1 ) );
printf( "Reverse of Number 2 is: %d\n", reverseIt( num2 ) );
}
int reverseIt( int num ) {
int tmp1, tmp2, resultant=0, divider=10;
tmp1 = num;
while( tmp1 %26gt; 0 ) {
tmp1 = num/divider;
tmp2 = num%divider;
resultant = (resultant*10) + tmp2;
divider = divider*10;
}
return resultant;
}
Should you have errors compiling this program, do let me know, I'll definitely help you further.
Reply:234==%26gt;432
#include %26lt;stdio.h%26gt;
#include %26lt;conio.h%26gt;
void main()
int i,j,x;
j=0;
printf(" Enter Num ");
scanf("%d",%26amp;x);
printf("X=%d\n",x);/*234
while(x)
{
b=x%10;
j=(j*10)+b;
x=x/10;
}
printf("Now =%d",j);/*432
getch();
}plz tell me if this program work properly
i just write it
Reply:int add(int a, int b) {
return a+b;
}
Reply:#include%26lt;stdio.h%26gt;
int add(int,int);
int sub(int,int);
int product(int,int);
int divide(int,int);
void swap(int,int);
void main()
{
int n1,n2,result;
char sym,choice;
printf("This Program is a program for calculator\n\n");
printf("enter the numbers");
do
{
scanf("%d%d",%26amp;n1,%26amp;n2);
printf("enter the symbel for operation to be performed addition(+), subtract(-), multiply(*), division(/) , swap(s)")
scanf("%c",%26amp;sym);
if(sym=='+')
{
result=add(n1,n2);
printf("\n%d",result);
}
if(sym=='-')
{
result=sub(n1,n2);
printf("\n%d",result);
}
if(sym=='*')
{
result= product(n1,n2);
printf("\n%d",result);
}
if(sym=='/')
{
result= divide(n1,n2);
printf("%d",result);
}
if(sym=='s')
{
swap(n1,n2);
}
printf("printing the same in reverse")
while(result%26gt;0)
{
sumOfDigits += result%10;
printf("%d",result%10);
result/=10;
}
printf("\nDo you wish to continue[y/n]");
scanf("%s",%26amp;choice);
}
while(choice=='y'||choice=='Y')
int add(int m1,int m2)
{
return(m1+m2);
}
int sub(int m1,int m2)
{
return(m1-m2);
}
int product(int m1,int m2)
{
return(m1*m2);
}
int divide(int m1,int m2)
{
return(m1/m2);
}
void swap(int m1, int m2)
{
printf("before swap m1=%d and m2=%d",m1,m2);
int tmp;
tmp=m1;
m1=m2;
m2=tmp;
printf("swaped numbers are m1=%d, and m2=%d ",m1,m2);
}
Reply:#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main()
{
int num1,num2;
printf("Enter 2 numbers\n");
scanf("%d%d",%26amp;num1,%26amp;num2);
add(num1,num2);
sub(num1,num2);
mul(num1,num2);
swap(num1,num2);
reverse(num1);
reverse(num2);
getch();
}
void add(int a,int b)
{
printf("Addition of 2 no's %d",a+b);
}
void sub(int a,int b)
{
printf("subtraction of 2 no's %d",a-b);
}
void mul(int a,int b)
{
printf("Multiplication of 2 no's %d",a*b);
}
void swap(int a,int b)
{
int c;
c=a;
a=b;
b=a;
printf("After Swapping %d %d",a,b);
}
void reverse(int num)
{
int sum=0,rev=0,digit;
while(num%26lt;0)
{
digit = num%10;
sum += digit;
rev = (rev * 10) + digit;
num /= 10;
}
printf("Reverse of number %d",rev);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment