0% found this document useful (0 votes)
59 views5 pages

Using If Else

The document contains code snippets demonstrating the use of if-else statements, switch statements, while loops, and for loops in C programming. The if-else statements code takes user input for two numbers and an operator and performs the calculation. The switch statements code performs the same calculation using a switch statement. The while loop code counts down from 10 to 1. The for loop code also counts down from 10 to 1 using a for loop. A final code snippet uses a for loop to print odd numbers.

Uploaded by

Keerthi Vasan S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views5 pages

Using If Else

The document contains code snippets demonstrating the use of if-else statements, switch statements, while loops, and for loops in C programming. The if-else statements code takes user input for two numbers and an operator and performs the calculation. The switch statements code performs the same calculation using a switch statement. The while loop code counts down from 10 to 1. The for loop code also counts down from 10 to 1 using a for loop. A final code snippet uses a for loop to print odd numbers.

Uploaded by

Keerthi Vasan S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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;

printf("result is a+b = %d",d);

}
else if(x =='-')

d=a-b;

printf("result is a-b= %d",d);

else if(x == '*')

d=a*b;

printf("result is a*b = %d",d);

else if(x == '/')

d=a/b;

printf("result is a/b = %d",d);

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);

printf("enter the opertion");

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:

printf("please enter the number like 1 to 4");

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();

For odd number

You might also like