Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Algorithms and Programming COMP151

Similar presentations


Presentation on theme: "Introduction to Algorithms and Programming COMP151"— Presentation transcript:

1 Introduction to Algorithms and Programming COMP151
LAB 5 If & If-else statements Introduction to Algorithms and Programming COMP151

2 Exercise 1: Write a program to check if the entered number by the user is even or odd.

3 #include<iostream>
using namespace std; int main() { int number,r; cout<<"Enter the value for number"<<endl; cin>>number; r=number%2; if(r==0) cout<<"The given number is even"<<endl; } else cout<<"The given number is odd"<<endl; return(0);

4 Exercise 2: Write a program to check if the entered number by the user is positive or negative or zero.

5 #include<iostream>
using namespace std; int main() { float number; cout<<"Enter the Value for Number"<<endl; cin>>number; if(number>0) cout<<"The given number is Positive"<<endl; } else If (number <0) cout<<"The given number is Negative"<<endl; cout<<"The given number Zero"<<endl; return(0);

6 Exercise 3: Write a program to check if the entered letter is vowel or not.

7 #include<iostream>
using namespace std; int main() { char letter; cout<<"Enter the character"<<endl; cin>>letter; if((letter=='a')||(letter=='A')||(letter=='e')|| (letter=='E')||(letter=='i')||(letter=='I')|| (letter=='o')||(letter=='O')||(letter=='u')|| (letter=='U')) cout<<"The given character is Vowel"<<endl; } else cout<<"The given character is not vowel"<<endl; return(0);

8 Exercise 3: Write a program to check if the Triangle is valid or not

9 #include<iostream>
using namespace std; int main() { float a, b, c, sum; cout<<"Enter the value of the three angles"<<endl; cin>>a>>b>>c; Sum= a+b+c; If (sum ==180) cout<<"The given triangle is valid"<<endl; else cout<<"The given triangle is not valid"<<endl; return(0); }


Download ppt "Introduction to Algorithms and Programming COMP151"

Similar presentations


Ads by Google