How to use if...else in C program?

Leave a Comment
      I am using if....else for making program easy. Using if....else to get output what we needed and run in the program. Here I used if....else for purpose of making calculator. 

Input :-

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ch;
clrscr();
printf("enter a");
scanf("%d",&a);
printf("enter b");
scanf("%d",&b);
printf("enter ch");
scanf("%d",&ch);
int c;
if(ch==1)
{
c=a+b;
printf("ans is %d",c);
}
else if(ch==2)
{
c=a-b;
printf("ans is %d",c);
}
else if(ch==3)
{
c=a*b;
printf("ans is %d",c);
}
else if(ch==4)
{
c=a/b;
printf("ans is %d",c);
}
else
{
printf("wrong ch");
}
getch();
}


Output:-


0 comments:

Post a Comment