0% found this document useful (0 votes)
2 views

C program Lab 3_v2

The document provides examples of various conditional statements in C programming, including if, if-else, if-else if-else, and nested if-else statements. It also presents problems for practice, such as finding the larger of two integers, checking if a number is a multiple of 7, and determining if a character is a vowel or consonant. Each example includes code snippets demonstrating the use of these statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C program Lab 3_v2

The document provides examples of various conditional statements in C programming, including if, if-else, if-else if-else, and nested if-else statements. It also presents problems for practice, such as finding the larger of two integers, checking if a number is a multiple of 7, and determining if a character is a vowel or consonant. Each example includes code snippets demonstrating the use of these statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE115L – Computing Concepts Lab

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

if - else if - else statement:

#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.

Sample Output 1: Sample Output 2:

Enter a number: 5 Enter a number: 49


5 is not a multiple of 7 49 is a multiple of 7

3. Write a C program that takes a character as input and checks whether it is a vowel or a consonant.

You might also like