C program Lab 3_v2
C program Lab 3_v2
Lab 04
if statement:
#include<stdio.h> #include<stdio.h>
int main() int main()
{ {
if(1) if(0)
printf("The statement is true"); printf("The statement is true");
return 0; return 0;
} }
if else statement:
#include<stdio.h> #include<stdio.h>
int main() int main()
{ {
int i=5,j=4; int i=2,j=4;
if(i>j) if(i>j)
printf("I is Greater than J"); printf("I is Greater than J");
else else
printf("J is Greater than I "); printf("J is Greater than I ");
return 0; return 0;
} }
#include<stdio.h> #include<stdio.h>
int main()
{ int main()
int num; {
printf("Enter a Number:"); char c;
scanf("%d",&num); printf("Enter a Character:");
scanf("%c",&c);
if(num>=90)
printf("Grade is A"); if(c=='A' || c=='a')
else if(num>=80 && num<90) printf("You pressed with A");
printf("Grade is B"); else if(c=='B' || c=='b')
else if(num>=70 && num<80) printf("You pressed with B");
printf("Grade is C"); else if(c=='C' || c=='c')
else printf("You pressed with C");
printf("Fail"); else
printf("You pressed a different key");
return 0; return 0;
}
}
Nested if else statement:
#include<stdio.h> #include<stdio.h>
int main()
int main() {
{ int i,j=3;
int i; printf("Enter a Number:");
printf("Enter a Number:"); scanf("%d",&i);
scanf("%d",&i);
if(i>0)
if(i>0) {
{ if(i<j)
if(i<5) {
{ printf("Greater than 0, less than J");
printf("Greater than 0, less than 5"); }
} else
else {
{ printf("Greater than J");
printf("Greater than 5"); }
} }
} else
{
return 0; printf("Less than 0");
}
} return 0;
}
Problems:
1. Write a C program that takes two integers as input and prints the larger of the two.
2. Write a C program that takes an integer as an input and determines whether it is a multiple of 7 or
not.
3. Write a C program that takes a character as input and checks whether it is a vowel or a consonant.