Professional Documents
Culture Documents
Use the tab escape sequence, \t, in the cout statement to separate the columns with tabs.
1 10 100 1000
2 20 200 2000
3 30 300 3000
4 40 400 4000
5 50 500 5000
6 60 600 6000
7 70 700 7000
8 80 800 8000
9 90 900 9000
SCREENSHOT
CODE
#include <iostream>
using namespace std;
int main() {
cout << "N\t10*N\t100*N\t1000*N\n";
for (int j = 1; j <= 10; j++) {
cout << j << "\t" << j * 10 << "\t" << j * 100 << "\t" << j * 1000 << "\t" << endl;
}
return 0;
}
TASK2:
Write a program that utilizes looping to produce the following table of values:
A A+2 A+4 A+6
3 5 7 9
6 8 10 12
9 11 13 15
12 14 16 18
15 17 19 21
SCREENSHOT
CODE
#include <iostream>
using namespace std;
int main () {
cout << "A\tA+2\tA+4\tA+6\n";
for(int a=3;a<=15;a+=3) {
cout << a << "\t" << a+2 << "\t" << a+4 << "\t" << a+6 << "\t" << endl;
}
return 0;
}
TASK3:
Write a program that calculates and prints the product of the odd integers from 1 to 50 and even integers
from 1 to 50.
SCREENSHOT
CODE
#include <iostream>
using namespace std;
int main() {
float productEven = 1, productOdd = 1, i, j;
for (i = 2, j = 1; i <= 50; i += 2, j += 2) {
productEven *= i;
productOdd *= j;
}
cout << "The product of all even numbers from 2 till 50 is: " << productEven << endl;
cout << "The product of all odd numbers from 1 till 50 is: " << productOdd << endl;
return 0;
}
TASK4:
Using Switch statement, write a program that displays the following menu for the food items available to
take order from the customer:
• B= Burger
• F= French Fries
• P= Pizza
• S= Sandwiches
The program inputs the type of food and quantity. It finally displays the total charges for the order
according to following criteria:
• Burger = Rs.100
• French Fries= Rs. 50
• Pizza= Rs. 800
• Sandwiches= Rs. 150
SCREENSHOT
CODE
#include <iostream>
using namespace std;
int main() {
char userOpt;
cout << "MENU FOR THE FOOD ITEM:\n";
cout << "PRESS:\nB FOR BURGER:\nF FOR FRENCH FRIES:\nP FOR PIZZA:\nS FOR SANDWICHES:\n";
cin >> userOpt;
switch (userOpt)
{
case 'b':case 'B':
cout << "Burger = RS.100\n";
break;
case 'f':case 'F':
cout << "French Fries = Rs. 50\n";
break;
case 'p':case 'P':
cout << "Pizza = RS. 800\n";
break;
case 's':case 'S':
cout << "Sandwiches = Rs. 150\n";
break;
default:
cout << "Option out of context. Try again\n";
break;
}
TASK5:
Write a program which input principal, rate and time from user and calculate compound (interest. You
can use library function.
CI = P(1+R/100)T – P
SCREENSHOT
CODE
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
float a, b, c,de;
cout << "Enter Principal: \n";
cin >> a;
cout << "Enter Rate: \n";
cin >> b;
cout << "Enter Time in seconds: \n";
cin >> c;
de = a * pow((1 + b / 100), c) - a;
cout << "Your calculated Compound Interest is : " << de;
}