Contents Chapter 2 To 6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

01 Write a Program to display a Hello World! in the output screen.

02 Write a Program to input Two characters and find their sum display on the screen.

03 Write a program that explain the concept of overflow and underflow.

04 Write a Program that inputs the radius of a circle and displays the circumference by using
formula 2 R. Store the value of in a constant by using DEFINE directive.

05 Write a program that perform all arithmatic operations on two variables.

06 Write a program that performs all compound assignment operations on an integer.

07 Write a Program that explains the difference of postfix increment operator and prefix
increment operator used as independent expression.

08 Write a program that explains the difference of postfrix increment opertaor and prefix
increment operator used as a part of a larger expression.

09 Write a program that explains the difference of postfix decrement and prefix decrement
operator used as independent expression.

10 Write a program that explains the difference of postfix decrement and prefix decrement
operator used as larger expression.

11 Write a program that solves the following expression:

a*b/(-c*31%13)*d

Assuming the values of variables are as follows:

a=10, b=20, c=15, d=8 , e=40 .

12 Write a program that divides two float varaiables and finds the remainder by using explict
casting.
13 Write a program that displays the sizes of different data types.

14 Write a program that inputs name, rollno, city and address from the user and then display
the vales on the screen. Output should be shown like: “Dear Your Name is Dastgir_Sabri
Faisalabad your place of birth and your Roll No is 49642 and your address is
123_Batala_colony”

15 Write a program that inputs name, age, city and address from the user and then display the
vales on the screen. Output should be shown like: “Dear Your Name is Ali Faisalabad your
place of birth and your age is 25 and your address is 123 Batala colony”

16 Write a program that display a message and value of integer and character varaiables.

17 Write program that adds two floating point numbers and shows the sum on screen.

18 Write a program to calculate and print the area of square with given height and width.

19 Write a program to display the following output using single cout statement.

**

***

****

20 Write a program that explains the use of setw manipulator.

21 Write a program that displays the value of different variables using setprecision
manipulator.

22 Write a program that displays the value of different variables using showpoint manipulator.

23 Write a program to displays the value of different variables using setfill manipulator.

24 Write a program that inputs name,age and address from the user and then displays on the
screen.

25 Write a program to caluclate the simple interest. It inputs principal amount, rate of interest
and the number of years and displays the simpple interest.

26 Write a program that inputs a character and displays its ASCII code.

27 Write a program that inputs dividend and divisor.It then calculates and displays the quotient
and remainder.

28 Write a program that inputs two numbers, swaps the value and then displays them.

29 Write a program that inputs two numbers, swaps, these values without using third variable
and display them.
30 Write a program that inputs the distance travelled and the speed of vehicle. It calculates the
time required to reach the destination and displays it.

31 Write a program that inputs base and height from the user. It calculates and displays the area
of a triangle by using the formula Area = 1/2 *Base*Height.

32 Write a program that inputs time in seconds and converts it into hh-mm-ss formate.

33 Write a program that gets temperature from the user in Celsius and converts it into
Fahrenheit using the formula F=9/5 *C=32.

34 Write a program that converts a person’s height from inches to centimeters using the
formula 2.54*height.

35 Write a program that inputs radius from the user and calculates area and circumference of
circle using the formula Area=π ^2 and circumference = 2πR.

Write a program that calculates the final velocity of an object by taking following inputs
36 from the user: vi = Initial velocity , a=acceleration, t=time sapn. Formula vf=vi=at.

Write a program that inputs a three-digit numbers from the user and display it in reverse
37 order. For example if the user and enter 123, it displays 321.

Write a program that inputs a five-digit number as input and reverse the number,
38
Write a program that inputs an even and odd number through keyboard, multiplies even
39 with 5 and odd with 3 and adda both results. It subtracts th results from 1000 and finally
prints the difference.

Write a program that generates the following output:


40
10

20

19

Use integer constant for 10. Arithmetic assignment operator to generate the 20 and
decrement operator to generate 19.

Write a program that will prompt the user to enter number of hours. It computes and
41 displays the number of weeks, days and hours within the input number of hours.

(e.g. 4000 hrs=23, weeks, 5 days, 16 hrs)

Write a program that will prompt the user to enter the current rates of electricity , gas and
42 petrol unit. Give each item’s rate and increment of 10%. Computer and displays the new
prices per unit of electricity, gas and petrol.

Write a program to print the following message:


43
44 Write a program that generates the following checker board by using eight output
statements.

45 Write a program that inputs marks and displays “Congratulations!You have passed.” If the
marks are 40 or more.

46 Write a program that inputs two numbers and finds whetger both are equal.

47 Write a program that inputs two numbers and finds if second number is square of first.

48 Write a program that inputs marks of three subjects. If the average of marks is more than
80, it displays two messages “You are above standard!” and “ Admission granted!”.

49 Write a program that inputs three numbers and displays the maximum number.

50 Write a program to input a number and determine whether it is positive, negative and zero.

51 Write a program that inputs a number and finds whether it is even and oddusing if-else
structure.

52 Write a program that inputs a year and finds a whether it is a leap year or not using if-else
structure.

53 Write a program that inputs a salary and grade. It adds 50% bonus if the grade is greater
than 15. It adds 25% bonus if the grade is 15 or less and then displays the total salary.

54 Write a program that inputs two integers. It detremines and prints if the first integer is a
multiple of second integer.

55 Write a program that inputs test score of a student and displays his grade according to the
following criteria;

Test Score Grade

>=90 A

80–89 B

70–79 C

60–69 D

Below 60 F

56 Write a program that calculates the electricity bill. The rates of a electricity per unit are as
follows:

If the units consumed are<=300, then the cost is Rs. 2 per unit.
If the units consumed are>300 and <=500, then the cost is Rs.5 per unit.

If the units consumed exceed 500 then the cost per unit is Rs.7

A line rent Rs. 150 is also added to the total bill and the surcharge of 5% extra if the bill
exceeds Rs.2000. calculates the total bill with all the conditions given above.

57 Write a programs that inputs radius and user’s choice. It calculates area of circle if user
enter 1 as choice. It calculatesv circumference if the user enters 2 as choice.

58 Write a program that inputs salary. If the salary. If the salary is 20000 or more, it deducts
7% of salary. If the salary is 10000 or more but less than 20000, it deducts 100 from the
salary. If salary is less than 10000, it deducts nothing. It finally displays the net salary.

59 Write a program that inputs three numbers and displays the smallest number by
using nested-if condition.

60 Write a program that inputs three numbers and displays whether all numbers are equal or
not by using nested-if condition.

61 Write a program that inputs three numbers and displays the maximum number by using
logical operators.

62 Write a program that inputs a character and displays whether it is vowel or not.

63 Write a program that allows the user to enter any character through the keyboard and
determines whether it is a capital letter,small case letter, a digit number or a special symbol.

64 Write a program that inputs a number and displays whether it is even or odd by using
logical operator “!”.
65 Write a program that inputs three digits and displays all possible combinations of these
digits.
66 Write a program that inputs number of weeks’s day and displays the name of the day.

67 Write a program that inputs a character from the user and checks whether it is vowel or
consonant.

68 Write a program that inputs a floating point number, an operator and another floating point
number. It displays the result by performing the operation on the given numbers. If the
operator is a division, it should check to make sure that the divisor is not equal to zero. If
the operator is not a + , - , * , or / then the program should print an error message.

69 Write a program that displays the following menu of the health club:

Standard Adult Membership.

Child Membership.
Senior Citizen Membership.

Quit the program

It inputs choice and number of months and calculates membership charges as follows:

Choice Charges Per Month

Standard Adult Membership RS.50

Child Membership Rs.20

Senior Citizen Membership Rs.30

70 Write a program that converts ASCII number to character and vice versa. The
Program should display the following menu:

Convert ASCII value to Character

Convert Character to ASCII value

71 Write a program that inputs marks of a student and displays “Pass” if marks are more than
40 and “Fail” otherwise by using conditional operator.

72 Write a program that inputs a number and displays whether it is divisible by 3 or not by
using conditional operator.

73 Write a program that displays “ Ghulam Dastgir Sabri” five times using goto statement.

74 Write a program that displays “Pakistan” for five times by using While loop.

75 Write a program that displays counting from 1 to 10 using while loop.


76 Write a program that displays five number and their sum using while loop.

77 Write a program that displays first five number with their squares using while loop.

78 Write a program that inputs a number from the users and displays a table of number using
while loop.

79 Write a program that inputs an integer and displays the sum of digits . for example program
should display 9 if user enters 135.

80 Write a program that inputs a number from user and displays the factorial of that number
using while loop.

81 Write a program that displays the degree to radian table using while loop.
82 Write a program that displays the sum of following series using while loop.

1+1/2+1/3+1/4…………………………….+1/100

83 Write a program that inputs a positive number.it then displays the sum of all odd numbers
and the sum of all even numbers from 1 to the number entered by user.

84 Write a program that inputs a number and checks whether it is an Armstrong number or not
.A number is an Armstrong number if sum of cubes of its digits is equal to the number itself
.For example ,371 is an Armstrong number since 3^3 + 7^3 + 1^3=371.

85 Write a program that inputs number until user enters a negative number . the program
calculates the average , maximum and minimum of all positive number .

86 Write a program that inputs a sentence from the user and count the numbers of words
and character in sentence.

87 Write a that inputs start and ending from user and displays all even numbers in the given
range using while loop.

88 Write a program that uses a while loop to enter number from user and then display.the loop
terminates whan user enter -1.

89 Write a program that inputs a number from user and display n fabonacci term.in fabonacci
sequence sum of two successive terms given the third term.

90 Write a program that inputs a number and check it is Fibonacci number or not.

91 Write a program that display back counting from 10 to 1using do while loop

92 Write a program that gets two number from users and displays the result of first number
raise to the power of second number using do while loop.

93 Write a program that inputs a number and checks whether it is a palindrome or not .A
palindrome is a number that reads the same backwards such as 62526 and 4994.

94 Write a program that gets starting and ending point from the user display all odd number in
this range using do while loop.

95 Write a program that reads the current state of a telephone line the user should enter w for
working state and d for dead state .Any other input should be invalid. Use the do while loop
to force the user to enter a valid input value.

96 Write a program that displays counting from 1 to 5 using for loop.

97 Write a program that displays the product of all odd number from 1 to 10 using for loop.
98 Write a program that inputs table number and length of table and then displays it using
for loop.
Write a program that finds the sum of the squares of integers from 1 to n. Where n is a positive value entered by the user (sum = 1^2 + 22 + 32 + ⋯ … … + 2) .
99
Write a program that inputs a number from the user and prints the lowest and highest digit
in number.
100
101 Write a program that inputs the value of x and range. It then calculates and print the sum of
the following series:

1+1/x+1/x^2+1/x^3+……….

102 Write a program that print the following

1 4 7 10………….40

103 Write a program to print the following series:

1 -4 7 -10 …………. -40

104 Write a program that inputs a number and checks whether it is a perfect number or not.A
perfect number is a number that is numerically equal to sum of its division. For example , 6
is a perfect number because the divisor of 6 are 1,2,3 and 1+2+3=6.

105 Write a program that inputs an integer and prints if it is prime or composite .A number
prime if it has factors 1 and itself,otherwise it is a composite number.

106 Write a program that inputs a number from user using for loop it displays number if it is
greater than 0 otherwise it inputs next number using continue statement.

107 Write a program that displays the sum of following series

1+3+5+7+………100

108 Write a program that inputs number from the user using for loop. If the number is greater
then 0.it is displayed and next number is input . The program exist the loop if the number is
0 or negative using break statement.

109 Write a program that inputs two numbers and displays the greatest common divisor of the
numbers.

110 Write a program that displays the product components of a number without repeating them.
For example if the user enters 24, it displays 24*1,12*2,8*3and 4*6.

111 Write a program that display following output.

112 Write a program that inputs the height of triangle and displays a triangle or characters for
example if the user enters 5, it displays the following.
113 Write a program that displays the following shape using nested loops .the outer loop should
be for loop and inner loop should be while loop.

114 Write a program that displays the following block using nested for loop.

115 Write a program that display following:

4 4 4 4

3 3 3

2 2

116 Write a program that displays the following shape using nested for loop.

117 Write a program that display following :

* *

* * *

* * * *

* ****

118 Write a program that displays the following output using loops.

1 2 3 4 5 6

1 2 3 4 5

1 2 3 4

1 2 3

1 2

119 Write a program that displays the following shape using nested for loops.

* *

* **

* ***

* ****
120 Write a program that display following output:

2 4

3 6 9

2 4

121 Write a program that inputs a character and display following shape:

& &

& &

& &

&&

&

122 Write a program that displays following output:

111 112 113 121 122 123 131 132 133 211 212 213

221 222 223 311 312 313 321 322 323 331 332 333

You might also like