Exp No7
Exp No7
1. If statement
#include <stdio.h>
void main()
if(b>a)
printf("B is greater");
}
2. If else ladder
#include <stdio.h>
int main()
{
int num1, num2;
printf("Please Enter Two different values\n");
scanf("%d %d", &num1, &num2);
if(num1 > num2)
{
printf("%d is Largest\n", num1);
}
else if (num2 > num1)
{
printf("%d is Largest\n", num2);
}
else
{
printf("Both are Equal\n");
}
return 0;
}
3.Nested if-else
#include <stdio.h>
void main()
int x=20,y=30;
if(x==20)
if(y==30)
}
4. If-else
int main()
{
else
{
printf("Both are Equal\n");
}
return 0;
}
XIII.Exercise
#include<iostream>
using namespace std;
class Day
{
private:
int day;
public:
void set_data()
{
cout<<"Enter no of day you want to display: ";
cin>>day;
}
void display_day()
{
switch (day)
{
case 1:
cout<<"MONDAY";
break;
case 2:
cout<<"TUESDAY";
break;
case 3:
cout<<"WEDNESDAY";
break;
case 4:
cout<<"THURSDAY";
break;
case 5:
cout<<"FRIDAY";
break;
case 6:
cout<<"SATURDAY";
break;
case 7:
cout<<"SUNDAY";
break;
default:
cout<<"INVALID INPUT";
break;
}
}
};
main()
{
Day d1;
d1.set_data();
d1.display_day();
return 0;
}
5. Switch case
#include <stdio.h>
void main()
{
int x ;
printf(“Please enter a number between 1 to 5:”);
scanf(“%d”,&x);
switch (x) {
case 1:
printf("Choice is 1");
break;
case 2:
printf("Choice is 2");
break;
case 3:
printf("Choice is 3");
break;
case 4:
printf("Choice is 4");
break;
case 5:
printf("Choice is 5");
break;
default:
printf("Invalid choice");
break;
}
return 0;
}
Looping Statements
1. While loop
#include <iostream>
int main() {
int i = 1;
while (i <= 5) {
++i;
return 0;
}
2. Do while loop
#include <iostream>
int main() {
int i = 1;
do {
++i;
return 0;
}
3.For loop
#include <iostream>
int main()
return 0;
}
XIII.Exercise
#include <iostream>
int main()
int n;
cin >> n;
if ( n % 2 == 0)
else
return 0;