You are on page 1of 16

Chapter 2

Q.12.
#include <iostream.h> #include <conio.h> void main() { clrscr(); cout << "******" << endl; cout << "******" << endl; cout << "******" << endl; cout << "******" << endl; getch(); }

Q.13.
#include <iostream.h> #include <conio.h> void main() { clrscr(); cout << "*" << endl; cout << "**" << endl; cout << "***" << endl; cout << "****" << endl; getch(); }

Q.14.
#include <iostream.h> #include <conio.h> #define _V1 'a' #define _V2 'e' #define _V3 'i' #define _V4 'o' #define _V5 'u' void main() { clrscr(); int a=0, e=2, i=4, o=6, u=8; cout << _V1 << ' ' << _V2 <<' '; cout << _V3 << ' ' << _V4 <<' '; cout << _V5 << endl; cout << a << ' ' << e << ' '; cout << i << ' ' << o << ' '; cout << u << endl; cout << 1 << ' ' << 3 << ' '; cout << 5 << ' ' << 7 << ' '; cout << 9 << endl; getch(); }

Q.15.

#include <iostream.h> #include <conio.h> void main() { clrscr(); int i1=1, i2=10, i3=100; int i4=1000, i5=10000; cout << i1 << ' ' << i2 << ' '; cout << i3 << ' ' << i4 << ' '; cout << i5; getch(); }

Q.16.
#include <iostream.h> #include <conio.h> void main() { clrscr(); cout << "TTTTT AAA Y Y" << endl; cout << " T A A Y Y " << endl; cout << " T A A Y " << endl; cout << " T AAA Y " << endl; cout << " T A A Y " << endl; cout << " T A A Y " << endl; cout << " T A A Y " << endl; getch(); }

Q.17.
#include <iostream.h> #include <conio.h> void main() { clrscr(); char ch, int i, float f; cout << "Enter a character. "; cin >> ch; cout << "Enter an integer. "; cin >> i; cout << "Enter a float number. "; cin >> f; cout<<"The character is "<<ch<<endl; cout<<"The integer is "<<i<<endl; cout<<"The float no. is "<<f<< endl; getch(); }

Q.19.
#include <iostream.h> #include <conio.h> void main() { clrscr(); int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10; cout << "Enter 10 numbers: "; cin>>i1>>i2>>i3>>i4>>i5; cin>>i6>>i7>>i8>>i9>>i10; cout << endl; cout <<"Your numbers are:"<< endl; cout << i1 << '\t' << i10 << endl; cout << i2 << '\t' << i9 << endl; cout << i3 << '\t' << i8 << endl; cout << i4 << '\t' << i7 << endl; cout << i5 << '\t' << i6 << endl; getch(); }

Q.20.
#include <iostream.h> #include <conio.h> void main() { clrscr(); int i1,i2,i3,i4,i5,i6,i7,i8,i9; cout << Enter nine integers: "; cin>>i1>>i2>>i3>>i4>>i5; cin>>i6>>i7>>i8>>i9; cout << endl; cout<<"Your numbers are: "<<endl; cout<<i1<<'\t'<<i2<<'\t'<<i3<<endl; cout<<i4<<'\t'<<i5<<'\t'<<i6<<endl; cout<<i7<<'\t'<<i8<<'\t'<<i9<<endl; getch(); }

Chapter 3
Q.14.
#include <iostream.h> #include <conio.h> void main() { clrscr(); long long num; cout << "Enter a number: "; cin >> num;

cout << "2nd rightmost digit is "; cout << (num % 100 / 10); getch(); }

Q.15.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float l, w; cout << "Enter length of rect: "; cin >> l; cout << "Enter width of rect: "; cin >> w; cout << "Area of rect is "; cout << (l * w) << endl; cout << "Perimeter of rect is "; cout << (2 * (l + w)); getch(); }

Q.16.
#include <iostream.h> #include <conio.h> #define _ONE_RADIAN 57.295779 void main() { clrscr(); float angle; cout << "Enter angle in degrees: "; cin >> angle; cout << "Angle in radian is "; cout << (angle / _ONE_RADIAN); getch(); }

Q.17.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float c; cout<<"Give centigrade temperature: "; cin >> c; float f = 32 + (c * 180.0 / 100); cout<<"Fehrenheit temperature is: "; cout<<f; getch(); }

Q.18.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float i; cout<<"Give measurement (inches): "; cin >> i; cout << "Measurement in foots: "; cout << (inches / 12) << endl; cout << "Measurement in yards: "; cout << (inches / 36) << endl; cout << "Measurement in cm: "; cout << (inches * 2.54) << endl; cout << "Measurement in meters: "; cout << (inches / 39.37) << endl; getch(); }

Q.19.
#include <iostream.h> #include <conio.h> void main() { clrscr(); int fib1, fib2, fib3; cout << "Enter two numbers: "; cin >> fib2, fib3; fib1 = fib2 + fib3; fib2 = fib3 + fib1; fib3 = fib1 + fib2; cout << "NEXT THREE NUMBERS " "IN FIBONACCI SERIES:" << endl; cout << fib1 << '\t'; cout << fib2 << '\t'; cout << fib3 << '\t'; getch(); }

Q.20.
#include <iostream.h> #include <conio.h> void main() { clrscr();

int i; cout << "Enter an integer value " "ranging [0-32767]: "; cin >> i; int d1 = i % 10; int d2 = i % 100 / 10; int d3 = i % 1000 / 100; int d4 = i % 10000 / 1000; int d5 = i % 100000 / 10000; cout<<d5<<'\t'<<d4<<'\t'<<d3<<'\t'; cout<<d2<<'\t'<<d1<<endl; cout<<d4<<'\t'<<d3<<'\t'; cout<<d2<<'\t'<<d1<<endl; cout<<d3<<'\t'<<d2<<'\t'<<d1<<endl; cout<<d2<<'\t'<<d1<< endl; cout<<d1<<endl; getch(); }

Q.21.
#include <iostream.h> #include <conio.h> #define _TV 400.00 #define _VCR 220.00 #define _REMOTE_CTRL 35.20 #define _CD_PLAYER 300.00 #define _TAPE 150.00 #define _TAX 8.25 void main() { clrscr(); int tv, vcr, _remote_ctrl, cd_player, tape; cout << "How many TVs were sold? "; cin >> tv; cout << "How many VCRs were sold? "; cin >> vcr; cout << "How many remote controllers were sold? "; cin >> remote_ctrl; cout << "How many CD players were sold? "; cin >> cd_player; cout << "How many tapes were sold? "; cin >> tape; cout << endl; cout << "QTY\tDESCRIPTION\tUNITPRICE\tTOTAL PRICE" << endl;

cout << "___\t___________\t_________\t___________" << endl << endl; float p1 = tv * _TV; float p2 = vcr * _VCR; float p3 = remote_ctrl * _REMOTE_CTRL; float p4 = cd_player * _CD_PLAYER; float p5 = tape * _TAPE; float subtotal = p1 + p2 + p3 + p4 + p5; float tax = subtotal * _TAX / 100; float total = subtotal + tax; cout << tv << "\tTV\t\t " << _TV << "\t\t " << p1 << endl; cout << vcr << "\tVCR\t\t " << _VCR << "\t\t " << p2 << endl; cout <<remote_ctrl<<"\tREMOTE CTRL\t "<<_REMOTE_CTRL<<"\t\t "<<p3<<endl; cout <<cd_player<<"\tCD PLAYER\t "<<_CD_PLAYER<<"\t\t "<< p4<<endl; cout << tape << "\tTAPE\t\t " << _TAPE << "\t\t " << p5 << endl; cout << " \t cout << " \t cout << " \t cout << " \t getch(); } \t \t___________" << endl << endl;

SUBTOTAL\t\t" << subtotal << endl; TAX\t\t" << tax << endl; TOTAL\t\t" << total << endl;

Others
Q.1.
#include <iostream.h> #include <conio.h> void main() { clrscr(); cout << "My name is Tayyab Akram"; cout << endl; cout << "My roll number is "; cout << 1102 << endl; cout << "The example of float is "; cout << 12.564 << endl; cout << "1st char of my name is "; cout << 'M' << endl; getch(); }

Q.2.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float r; cout << "Enter radius of sphere: "; cin >> r;

float a = 4.0 * 3.14 * (r * r); float v = 4.0/3.0 * 3.14 * (r*r*r); cout << "The area is "<<a<<endl; cout << "The volume is "<<v<<endl; getch(); }

Q.3.
#include <iostream.h> #include <conio.h> #include <math.h> void main() { clrscr(); float a, b, c; cout << "Enter sides of triangle "; cin >> a, b, c; float s = (a + b + c) / 2.0; float area = sqrt(s * (s-a) * (s-b) * (s-c)); cout<<"Area of triangle is "<<area; getch(); }

Q.4.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float miles; cout << "Enter distance in miles "; cin >> miles; cout<<"Distance in kilometers: "; cout<<(miles * 1.609); getch(); }

Q.5.
#include <iostream.h> #include <conio.h> void main() { clrscr(); long a, b, c, d; cout << "Enter 4 numbers: "; cin >> a, b, c, d; long sum = a + b + c + d; float average = (a+b+c+d) / 4.0; long product = a * b * c * d; cout << "Sum of numbers is: ";

cout << sum << endl; cout << "Average of numbers is: "; cout << average << endl; cout << "Product of numbers is: "; cout << product; getch(); }

Q.6.
#include <iostream.h> #include <conio.h> void main() { clrscr(); long age; cout << "Enter your age in years "; cin >> age; long m = age * 12; long d = age * 365; cout <<"Age in months: "<<m<<endl; cout <<"Age in days: "<<d; getch(); }

Q.7.
#include <iostream.h> #include <conio.h> void main() { clrscr(); int n; cout << "Enter a number: "; cin >> n; cout << "The square is " << (n*n); cout << endl; cout << "The cube is " << (n*n*n); getch(); }

Q.9.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float liters; cout << "Enter the petrol " "(in liters) of a car: "; cin >> liters; float distance = liters * 5.3; cout << "The car can travel ";

cout << distance << " miles"; getch(); }

Q.11.
#include <iostream.h> #include <conio.h> void main() { clrscr(); float tmpf; cout<<"Give fahrenheit temperature "; cin >> tmpf; float tmpd = 5.0/9.0 * (tmpf-32); cout << "Degrees temperature: "; cout << tmpd; getch(); }

Q.12.
#include <iostream.h> #include <conio.h> void main() { clrscr(); int val; cout<<"Enter three digit number "; cin >> val; cout << "Result: " << endl; cout << (val%1000/100) << endl; cout << (val%100/10) << endl; cout << (val%10) << endl; getch(); }

Q.13.
#include <iostream.h> #include <conio.h> void main() { clrscr(); cout << "1 2 3 4 5\n6 7 8 9 10"; getch(); }

Q.14.
#include <iostream.h> #include <conio.h> void main() {

clrscr(); float l, w, h; cout << "Enter length of cube: "; cin >> l; cout << "Enter width of cube: "; cin >> w; cout << "Enter height of cube: "; cin >> h; float vol = l * w * h; cout << "The volume of cube is: "; cout << vol; getch(); }

Q.15.
#include <iostream.h> #include <conio.h> #include <math.h> void main() { clrscr(); float x1, y1, x2, y2; char stmt1[] = "Enter 1st point: "; cout << stmt1; cin >> x1; gotoxy(sizeof(stmt1) + 6, 1); cout << ", "; cin >> y1; char stmt2[] = "Enter 2nd point: "; cout << stmt2; cin >> x2; gotoxy(sizeof(stmt2) + 6, 2); cout << ", "; cin >> y2; float x = x2 - x1; float y = y2 - y1; float dist = sqrt((x*x) + (y*y)); cout << "The distance between " "the points is: " << dist; getch(); }

Q.16.
#include <iostream.h> #include <conio.h>

void main() { clrscr(); int a, b, c, t; cout << "Enter three integers: "; cin >> a >> b >> c; t = a; a = b; b = c; c = t; cout << "The swapped values are: "; cout << a << ' ' << b << ' ' << c; getch(); }

Q.17.
#include <iostream.h> #include <conio.h> int main() { clrscr(); float r, angle; cout << "Enter radius of a " "convex lens (in meters): "; cin >> r; cout << "Enter angle in degrees: "; cin >> angle; float l = r*(3.14/180.0*angle); cout << "The length of arc of " "convex lens is: " << length; getch(); }

Q.18.
#include <iostream.h> #include <conio.h> int main(){ clrscr(); float p; cout << "Enter mass in pounds: "; cin >> p; cout<<"Mass in kilograms "<<(p/2.205); getch(); }

Q.19.
#include <iostream.h> #include <conio.h> int main() { clrscr(); float angle, r; cout << "Enter the angle of a " "sector of a circle: "; cin >> angle; cout << "Enter radius of circle: "; cin >> r; float area = r * r * angle / 2.0; cout << "The area of the sector " "of the circle is: "<<area; getch(); }

Q.21.
#include <iostream.h> #include <conio.h> int main() { clrscr(); char letter; cout<<"Enter a letter of English "; cin >> letter; cout<<"The next two letters are: "; cout<< (char)(letter + 1) << ", "; cout<< (char)(letter + 2); getch(); }

Q.22.
#include <iostream.h> #include <conio.h> int main() { clrscr(); long input; cout<<"Enter a 5 digit integer: "; cin >> input; int i1 = input / 10000; int i2 = input % 10000 / 1000; int i3 = input % 1000 / 100; int i4 = input % 100 / 10; int i5 = input % 10; int sum = i1 + i2 + i3 + i4 + i5; cout << "Sum of integers: " << sum;

getch(); }

Q.23.
#include <iostream.h> #include <conio.h> int main() { clrscr(); long salary; cout<< "Enter your basic salary: "; cin >> salary; double dearness =salary*35.0/100.0; double rent = salary * 25.0/100.0; double gross =salary-dearness-rent; cout << "Gross salary: " << gross; getch(); }

Q.24.
#include <iostream.h> #include <conio.h> int main() { clrscr(); int h1, m1, s1, h2, m2, s2; cout<<"Enter 1st time [hh:mm:ss] "; cin >> h1; cin.ignore(1, ':'); cin >> m1; cin.ignore(1, ':'); cin >> s1; cout<<"Enter 2nd time [hh:mm:ss] "; cin >> h2; cin.ignore(1, ':'); cin >> m2; cin.ignore(1, ':'); cin >> s2; int s3 = s1 + s2; int s = s3 % 60; int m3 = m1 + m2 + (s3 / 60); int m = m3 % 60; int h3 = h1 + h2 + (m3 / 60); int h = h3 % 24; int d = h3 / 24; cout<<"Sum of times with next "; cout<< d << " day/days: "; cout<< h << ':' << m << ':' << s; getch(); }

Q.25.

#include <iostream.h> #include <conio.h> #include <math.h> int main() { clrscr(); float amount, rate, time; cout << "Enter principal amount: "; cin >> amount; cout << "Enter rate of interest: "; cin >> rate; cout<<"Enter total time in years "; cin >> time; float ci = amount * pow(1 + rate/100, time) - amount; cout << "Compound interest: "<< ci; getch(); }

Q.26.
#include <iostream.h> #include <conio.h> int main() { clrscr(); char number; cout << "Enter a number: "; cin >> number; cout << "The ASCII code of " << number << " is " << (int)number; getch(); }

Q.27.
#include <iostream.h> #include <conio.h> int main() { clrscr(); cout << "Number\tSquare\tCube" << endl; cout << " 1 \t 1 \t 1 " << endl; cout << " 2 \t 4 \t 8 " << endl; cout << " 3 \t 9 \t 27" << endl; cout << " 4 \t 16 \t 64" << endl; cout << " 5 \t 25 \t 125" << endl; getch(); }

You might also like