CSL_113-Lab03-Selection.docx - Exercise 1:Write a C Program that read a float input from user and store it in variable amount Add 16 to an integer num

# CSL_113-Lab03-Selection.docx - Exercise 1:Write a C Program...

This preview shows page 1 - 4 out of 11 pages.

Exercise 1:- Write a C++ Program that read a float input from user and store it in variable amount. Add 16 to an integer num if the value of amount in greater than 5.4. Print out the results of both variables on screen. #include <iostream> using namespace std; int main() { int num=16; float x, result; cout<< "Enter your value" ; cin>>x; result=num+x; if (result>5.4) { cout<< "x=" <<x<<endl; cout<< "num=" <<num<<endl; } return 0; } Output:-
Exercise 2:- Write a C++ Program that read three input from user and returns the smallest one. #include <iostream> using namespace std; int main() { int a, b, c, d; cout << "Enter the value of a: " ; cin >> a; cout << "Enter the value of b: " ; cin >> b; cout << "Enter the value of c: " ; cin >> c; if (a < b && b < c) { d = a; } else if (b < a && b < c) { d = b; } else { d = c; } cout << "the smallest value among " << a << ", " << b << " and " << c << " is: " << d << endl; return 0; } Output:-
Exercise 3:- Write a C++ Program that read an alphabet (e.g. a, b, c, d,…..z) and display whether the input alphabet is a vowel (i.e. a, e, i, o, u) or consonant. #include <iostream> using namespace std; int main() { char ch; cout<< "Enter an alphabet : " ; cin>>ch; if (ch== 'a' || ch== 'A' || ch== 'e' || ch== 'E' || ch== 'i' || ch== 'I' || ch== 'o' || ch== 'O' || ch== 'u' || ch== 'U' ) { cout<< "\n\nThis is a vowel" ; } else { cout<< "\n\nThis is not a vowel" ; } return 0; } Output:-

#### You've reached the end of your free preview.

Want to read all 11 pages?

• Spring '17
• tarwan