Using If Else
Using If Else
Using If Else
#include<stdio.h>
#include<stdlib.h>
int clearch()
while((getchar())^'\n');
int main()
int a,b,d;
char x;
printf("enter a\n");
scanf("%d",&a);
printf("enter b\n");
scanf("%d",&b);
printf("enter operation\n");
clearch();
x = getch();
if(x =='+')
d=a+b;
}
else if(x =='-')
d=a-b;
d=a*b;
d=a/b;
getch();
return 0;
Using switch
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int clearch()
while((getchar())^'\n');
}
int main()
int a,b,d;
char x;
printf("enter a\n");
scanf("%d",&a);
printf("enter b\n");
scanf("%d",&b);
clearch();
x = getch();
printf("%c",x);
switch(x)
case '+':
d=a+b;
printf("result is a+b=%d",d);
break;
case '-':
d=a-b;
printf("result is a-b=%d",d);
break;
case '*':
d=a*b;
printf("result is a*b=%d",d);
break;
case '/':
d=a/b;
printf("result is a/b=%d",d);
break;
default:
break;
clearch();
getch();
return 0;
While loop
#include<stdio.h>
#include<stdlib.h>
int main()
int count=10;
while(count>=1)
printf("%d\n",count);
//count=count-1;
count--;
}
getch();
For loop
#include<stdio.h>
#include<stdlib.h>
int main()
int count;
for(count=10;count>=1;count--)
printf("%d\n",count);
//count=count-1;
getch();