LAB4.docx - CSL-113 Computer Programming Lab Semester BS CS – 01 Exercise 1 Write a C Program that read a float(amount and an int(num input from user

# LAB4.docx - CSL-113 Computer Programming Lab Semester BS CS...

• 12

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

CSL-113: Computer Programming Lab Semester BS CS – 01 Exercise 1 Write a C++ Program that read a float (amount) and an int (num) input from user. Add both (amount and num) numbers and store them in two different int (a) and float (b) variables. Display the outputs of a and b variables. Also if outputs are greater than 16 print “value of a & b > 16” else print “value of a & b < 16” Program #include <iostream> using namespace std; int main() { //declaration int num, a; float amount, b; //input of float and integer data type cout << "enter an integer number: " ; cin >> num; cout << "enter a float number: " ; cin >> amount; //sum of amount and num is saved into variable a of datatype integer a = num + amount; //sum of amount and num is saved into variable b of datatype float b = num + amount; //value of a and b is printed on the screen cout << "value of a is " << a << "\nvalue of b is " << b << endl; //checking the value of a and b is greater than 16 or not if (a > 16 && b > 16) // if true the below statement will be executed { cout << "value of a and b is greater than 16" << endl; } else //if value of a and b is less than 16 then the below statement will be exceuted { cout << "value of a and b is less than 16" << endl; } system( "pause" ); return 0; } Output Exercise 2 Department of Computer Sciences Page: 15 Semester BSCS 01 CSL-113: Computer Programming Lab Lab 04: Decision Statements
CSL-113: Computer Programming Lab Semester BS CS – 01 Write a C++ Program that read three input from user and returns the smallest one. Program #include <iostream> using namespace std; int main() { //declaration int a, b, c; //input cout << "enter number 1: " ; cin >> a; cout << "enter number 2: " ; cin >> b; cout << "enter number 3: " ; cin >> c; if (a < b && a < c) //checking if number 1 is less than 2 and 3 or not { //if test expression is true, then below statement will only be executed cout << a << " is the smallest number" << endl; } else if (b < a && b < c) //if previous test expression fails, then checking if number2 is less than 1 and 3 { //if test expression is true, then below statement will only be executed cout << b << " is the smallest number" << endl; } else { //if all test expression fails, then below statement will be executed by default cout << c << " is the smallest number" << endl; } system( "pause" ); return 0; } Output Exercise 3 Department of Computer Sciences Page: 16 Semester BSCS 01 CSL-113: Computer Programming Lab Lab 04: Decision Statements
CSL-113: Computer Programming Lab Semester BS CS – 01 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.

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

Want to read all 12 pages?

• Summer '19

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern