#Include #Include Using Namespace Int Int
#Include #Include Using Namespace Int Int
1. What is the correct variable type for storing the following data:
a. The number of books in a bookshelf
int
b. The cost of this book
float
c. The number of people in the world
double
d. The word Hello
char
2. Write a program that calculates and prints sum, difference and product of two numbers. Also,
use this program to calculate remainder and quotient in division of these numbers. Display
the output on the screen.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
int n1,n2;
cout << "Enter First number : "; cin >> n1;
cout << "Enter Second number: "; cin >> n2;
cout << n1<< "+" <<n2<< "=" << n1+n2 << endl;
cout << n1<< "-" <<n2<< "=" << n1-n2 << endl;
cout << n1<< "*" <<n2<< "=" << n1*n2 << endl;
cout << n1<< "/" <<n2<< "=" << n1/n2 << endl;
cout << n1<< "%" <<n2<< "=" << n1%n2 << endl;
system("PAUSE");
return 0;
}
3. Write a program that gets 6 integers from the user and displays the sum, average and product
of these numbers on screen.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(){
float n1,n2,n3,n4,n5,n6,sum,prod,avg;
cout << "Enter Six Numbers : ";
cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
prod = n1*n2*n3*n4*n5*n6;
sum = n1+n2+n3+n4+n5+n6;
avg = sum/6;
cout <<"Product = " << prod <<endl;
cout <<"Sum
= " << sum <<endl;
cout <<"Average = " << avg <<endl;
system("PAUSE");
return 0;
}