Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, February 9, 2011

C5 : Calculations with numbers(Switch and goto)


Back to Home   &  C


A )))//Program to enter 2 numbers from keyboard and find its Addition,Subtraction,Multiplication and Division as per user's choice.


#include<stdio.h>
#include<conio.h>
void main()
            {
            clrscr();
            int a,b,c,d;
            printf("Enter 2 nos\n");
            scanf("%d%d",&a,&b);
            p:
            printf("Enter your choice\n");
            printf("1-add,2-sub,3-multiply,4-div\n");
            scanf("%d",&c);
           switch(c)
                        {
                        case 1:
d=a+b;
printf("Result=%d\n\n==========\n",d);
break;
                        case 2:
d=a-b;
  printf("Result=%d\n\n==========\n",d);
break;
                       case 3:
d=a*b;
printf("Result=%d\n\n==========\n",d);
break;
                      case 4:
d=a/b;
printf("Result=%d\n\n==========\n",d);
break;
                      case 5:
                      goto n;
                      break;
         default:
printf("Error !!!\n\n==========\n");
   }
   goto p;
   getch();
   n:
}
-----------------------------------------------------
Output
Enter 2 numbers (Enter any 2 numbers as per your choice)
2
3
Enter your choice
1-add,2-sub,3-multiply,4-div
4
Result=6
===============================================
B )))//Program to enter 2 numbers from keyboard and find its Addition,Subtraction,Multiplication and Division.



#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
printf("Enter 2 numbers\n");
scanf("%d%d",&a,&b);
c=a+b;
printf("Result of Addition=%d\n",c);
c=a-b;
printf("Result of Subtraction=%d\n",c);
c=a*b;
printf("Result of Multiplication=%d\n",c);
c=a/b;
printf("Result of Division=%d\n",c);
getch();
}
-----------------------------------------------------
Output
Enter 2 numbers
3
2
Result of Addition=5
Result of Subtraction=1
Result of Multiplication=6
Result of Division=1



Back to Home   &  C

No comments: