EmbLogic's Blog

simple ‘calculator’ using do-while…

1#include<stdio.h>
2 #include<math.h>
3 int main()
4 { int a,b,i;
5   printf(“\n\nenter two no.s : “);
6   scanf(“%d %d”,&a,&b);
7         do
8         {
9           printf(“\nenter 1 for ‘+’ : “);
10           printf(“\nenter 2 for ‘-’ : “);
11           printf(“\nenter 3 for ‘*’ : “);
12           printf(“\nenter 4 for ‘/’ : \n”);
13
14           scanf(“%d”,&i);
15
16              switch(i)
17              {
18                      case 1: printf(“\nthe ans. is : %d\n”,a+b);
19                         break;
20                      case 2: printf(“\nthe ans. is :%d\n”,a-b);
21                         break;
22                      case 3: printf(“\nthe ans. is :%d\n”,a*b);
23                         break;
24                         case 4: printf(“\nthe ans. is :%d\n”,a/b);
25                         break;
26                 default:printf(“\nenter valid option\n”);
27              }
28
29
30         }
31
32         while(i!=0);
33 }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>