Revision
Revision
Revision
Write a program that reads in the radius of a circle and prints the circle’s
diameter, circumference and area. Use the constant value 3.14159 for pie. Do
these calculations in output statements.
ANSWER 1
#include <iostream>
using namespace std:
int main()
{
int radius;
cout << "Enter the circle radius: ";
cin >> radius;
cout << "Diameter is " << radius * 2.0
<< "\nCircumference is " << 2 * 3.14159 * radius
<< "\nArea is " << 3.14159 * radius * radius << endl;
return 0;
}
2) EXP
ANSWER 2
#include <iostream>
using namespace std;
main()
{
int a, b, c, d;
cout<<"Enter the value A : "; cin>>a;
cout<<"Enter the value B : "; cin>>b;
c = a * b;
d = a / b;
cout<<"Answer C = A * B is "<<c<<ends;
cout<<"\n Answer D = A / B is "<<d<<ends;
}
3) EXP
ANSWER 3
#include <iostream>
using namespace std;
main()
{
int a = 250;
cout<<"Use of Manipulatorsr"<<"\n\n";
cout<<"Decimal Octal Hexadecimal"<<endl;
cout<<"----------------------------"<<"\n";
for(a=250;a<=260;a++)
{
cout<<dec<<a<<" ";
cout<<oct<<a<<" ";
cout<<hex<<a<<endl;
}
4) EXP
ANSWER 4
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;
if (n < 10)
cout << "less than 10" << endl;
else if (n > 5)
cout << "greater than 5" << endl;
else
cout << "not interesting" << endl;
return 0;
}
5) EXP
Write a program that input three integers from the keyboard and prints the
sum, average, product, smallest and largest of these numbers.
ANSWER 5
#include <iostream>
using namespace std:
int main()
{
int num1, num2, num3, smallest, largest; // declaration
cout << "Input three different integers: "; //
cin >> num1 >> num2 >> num3; //input
largest = num1; // assume first number is largest
if ( num2 > largest ) // is num2 larger?
largest = num2;
if ( num3 > largest ) // is num3 larger?
largest = num3;
smallest = num1; // assume first number is smallest
if ( num2 < smallest )
smallest = num2;
if ( num3 < smallest )
smallest = num3;
cout << "Sum is " << num1 + num2 + num3
<< "\nAverage is " << (num1 + num2 + num3) / 3
<< "\nProduct is " << num1 * num2 * num3
<< "\nSmallest is " << smallest
<< "\nLargest is " << largest << endl;
return 0;
}
6) EXP
Write a program that prints a box, an oval, an arrow and a diamond.
ANSWER 6
7) EXP
Write a program that reads an integer and determines and prints whether it is
odd or even.
ANSWER 7
#include <iostream>
using namespace std:
int main()
{
int num;
cout << "Enter a number: ";
cin >> num;
if ( num % 2 == 0 )
cout << "The number " << num << " is even." << endl;
if ( num % 2 != 0 )
cout << "The number " << num << " is odd." << endl;
return 0;
}
8) EXP
ANSWER 8
#include <iostream>
using namespace std;
int main() {
char oper;
float num1, num2;
cout << "Enter an operator (+, -, *, /): ";
cin >> oper;
cout << "Enter two numbers: " << endl;
cin >> num1 >> num2;
switch (oper) {
case '+':
cout << num1 << " + " << num2 << " = " << num1 + num2;
break;
case '-':
cout << num1 << " - " << num2 << " = " << num1 - num2;
break;
case '*':
cout << num1 << " * " << num2 << " = " << num1 * num2;
break;
case '/':
cout << num1 << " / " << num2 << " = " << num1 / num2;
break;
default:
// operator is doesn't match any case constant (+, -, *, /)
cout << "Error! The operator is not correct";
break;
}
return 0;
}