You are on page 1of 6

Console I/O and Conditional Statements:

1. A cashier has currency notes of denominations 10, 50 and 100. Write a C program which accepts
an amount to be withdrawn, and prints the total number of currency notes of each denomination
the cashier will have to give to the withdrawer.

Output:
Enter the total amount to be withdrawn : 370
Total number of currency notes to be given is : 6

2. In a town, the percentage of men is 52. The percentage of total literacy is 48. If total percentage
of literate men is 35 of the total population, write a program to find the total number of illiterate
men and women if the population of the town is 80,000.

Output:
The number of illiterate men : 13600
The number of illiterate women : 28000

3. If a five-digit integer is input through the keyboard, write a program to print a new number by
adding one to each of its digits. For example, if the number that is input is 12391 then the output
should be displayed as 23402.

Output:
Enter the five digit number : 19875
The final number is: 20986

4. Read a five-letter word into the computer, then encode the word on a letter-by-letter basis by
subtracting 30 from the numerical value that is used to represent each letter. Thus if the ASCII
character set is being used, the letter a (which is represented by the value 97) would become a C
(represented by the value 67),etc. Write out the encoded version of the word.

Output:
Enter the string: abcde
CDEFG

5. Write a program to check whether a triangle is valid or not, when (i) the three angles of the
triangle
are entered through the Keyboard (ii) three sides of the triangle are entered through the keyboard.

Output:
Enter the angles: 30
60
90
Enter the sides : 2 3 4
The triangle is valid.

6. Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if all the three points
fall on one straight line.

Output:
Enter the points : 1 2 5 10 3 6
The point are on a line.
7. Given the coordinates (x, y) of a center of a circle and its radius, write a program which will
determine whether a point lies inside the circle, on the circle or outside the circle. (Hint: #include
<math.h>. Use sqrt( ) and pow( ) functions)

Output:
Enter the radius of the circle: 5
Enter the coordinates of the center: 3 4
Enter the coordinates of the point to be checked: 2 2
The point is inside the circle

8. Any character is entered through the keyboard, write a program to determine whether the
character entered is a capital letter, a small case letter, a digit or a special symbol.

Output:
Enter the character: 9
It is a digit.

9. Given as input an integer number of seconds, write a program to print as output the equivalent
time in hours, minutes and seconds. Recommended output format is something like 7322 seconds
is equivalent to 2 hours 2 minutes 2 seconds.

Output:
Enter the number of seconds: 3622
Total time is 1 : 0 : 22

10. Write a program which accepts two number X, Y and creates a third number Z by appending Y
after X. Example: if X=12 and Y=345 then Z=12345.

Output:
Enter the numbers:354
985
The modified number is: 354985
11. A certain grade of steel is graded according to the following conditions:
(i)Hardness must be greater than 50, (ii) Carbon content must be less than 0.7, (iii) Tensile strength
must be greater than 5600. The grades are as follows:
Grade is 10 if all three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of hardness, carbon content and tensile
strength of the steel under consideration and output the grade of the steel.

Output:
Enter the hardness, carbon content and the tensile strength of the steel: 51
0.6
5611
The grade of the steel is: 7.000000
Loops:
1.Write a program which accepts a number n and prints all prime factors of n.

Output:
Enter the number: 93
3 31
2. Write a program to generate all combinations of digit 1, 2 and 3 using for loop.

Output:
123 132 213 231 312 321

3. Write a program to print the multiplication table of the number entered by the user. The table
should get displayed in the following form.
29 * 1 = 29
29 * 2 = 58

Output:
31 * 1 = 31
31 * 2 = 62
31 * 3 = 93
31 * 4 = 124
31 * 5 = 155
31 * 6 = 186
31 * 7 = 217
31 * 8 = 248
31 * 9 = 279
31 * 10 = 310

6. Write a program to print out all Armstrong numbers between 1 and 500. If the sum of cubes of
each digit of the number is equal to the number itself, then the number is called an Armstrong
number.

Output:
1 153 370 371 407

7. An important property of square numbers: If a natural number is a square number, then it has to
be the sum of Successive Odd Numbers starting from 1.
For example:
Perfect Square Sum of Odd Numbers
4= 1 + 3
9= 1 + 3 + 5
16= 1 + 3 + 5 + 7
25 = 1 + 3 + 5 + 7 + 9
36 = 1 + 3 + 5 + 7 + 9 + 11
49 = 1 + 3 + 5 + 7 + 9 + 11 + 13
64 = 1 + 3 + 5 + 7 + 9 + 11 + 13 + 15
Now using this property, find the square root of any perfect square.

Output:
Enter the perfect square: 49
Square root is: 7
8. Write a program which reads a positive integer value, and compute the following sequence: if the
number is even, halve it; if it’s odd, multiply by 3 and add 1. Repeat this process until the value is
1, printing out each intermediate value. Finally the program should print how many of these
operations were performed. Typical output might be:
Inital value is 3
Next value is 10
Next value is 5
Next value is 16
Next value is 8
Next value is 4
Next value is 2
Next value is 1
Number of operations is 7

Output:
Enter the number: 24
Initial value is: 24
The next value is: 12
The next value is: 6
The next value is: 3
The next value is: 10
The next value is: 5
The next value is: 16
The next value is: 8
The next value is: 4
The next value is: 2
The next value is: 1

9. Write a program to print all the ASCII values and their equivalent characters using a while loop.
The ASCII values vary from 0 to 255.

Output:
32 33 ! 34 " 35 # 36 $ 37 % 38 & 39 ' 40 ( 41 ) 42 * 43 + 44 , 45 - 46 . 47 / 48 0 49 1 50 2 51 3 52 4 53
5 54 6 55 7 56 8 57 9 58 : 59 ; 60 < 61 = 62 > 63 ? 64 @ 65 A 66 B 67 C 68 D 69 E 70 F 71 G 72 H 73 I
74 J 75 K 76 L 77 M 78 N 79 O 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W 88 X 89 Y 90 Z 91 [ 92 \ 93 ] 94
^ 95 _ 96 ` 97 a 98 b 99 c 100 d 101 e 102 f 103 g 104 h 105 i 106 j 107 k 108 l 109 m 110 n 111 o 112
p 113 q 114 r 115 s 116 t 117 u 118 v 119 w 120 x 121 y 122 z 123 { 124 | 125 } 126 ~ 127  128 Ç
129 ü 130 é 131 â 132 ä 133 à 134 å 135 ç 136 ê 137 ë 138 è 139 ï 140 î 141 ì 142 Ä 143 Å 144 É 145
æ 146 Æ 147 ô 148 ö 149 ò 150 û 151 ù 152 ÿ 153 Ö 154 Ü 155 ¢ 156 £ 157 ¥ 158 ₧ 159 ƒ 160 á 161 í
162 ó 163 ú 164 ñ 165 Ñ 166 ª 167 º 168 ¿ 169 ⌐ 170 ¬ 171 ½ 172 ¼ 173 ¡ 174 « 175 » 176 ░ 177 ▒
178 ▓ 179 │ 180 ┤ 181 ╡ 182 ╢ 183 ╖ 184 ╕ 185 ╣ 186 ║ 187 ╗ 188 ╝ 189 ╜ 190 ╛ 191 ┐ 192 └
193 ┴ 194 ┬ 195 ├ 196 ─ 197 ┼ 198 ╞ 199 ╟ 200 ╚ 201 ╔ 202 ╩ 203 ╦ 204 ╠ 205 ═ 206 ╬ 207 ╧
208 ╨ 209 ╤ 210 ╥ 211 ╙ 212 ╘ 213 ╒ 214 ╓ 215 ╫ 216 ╪ 217 ┘ 218 ┌ 219 █ 220 ▄ 221 ▌ 222 ▐
223 ▀ 224 α 225 ß 226 Γ 227 π 228 Σ 229 σ 230 µ 231 τ 232 Φ 233 Θ 234 Ω 235 δ 236 ∞ 237 φ 238 ε
239 ∩ 240 ≡ 241 ± 242 ≥ 243 ≤ 244 ⌠ 245 ⌡ 246 ÷ 247 ≈ 248 ° 249 ∙ 250 ∙ 251 √ 252 ⁿ 253 ² 254 ■ 255

10. Write a program to find the octal equivalent of the entered integer.

Output:
Enter the number: 37
The octal equivalent is: 45
11. Write a program to add first seven terms of the following series using a for loop:
1/1!+2/2!+3/3!+⋯

Output:
2.718056

Arrays:
1. Write a program in C to read n number of values in an array. After that, count the total number of
duplicate elements in that array. Then copy the elements except the duplicate elements of that
array into another array and display this array in reverse order.

Output:
Enter the elements of the array: 6 6 2 4 9 6 1 3 3 5 2
1234569

2. Write a menu-driven program for accepting values in two square matrix of 3x3 dimension and
generate their sum, difference and product.

Output:
Enter the number corresponding to the required operation: 1. Sum
2. Difference
3. Product3
Enter the values of first matrix: 1 2 3
456
789
Enter the values of the second matrix: 9 8 7
654
321
The product of the two arrays is:
30 24 18
84 69 54
138 114 90

4. Write a C program which accepts roll numbers of ten students and marks obtained by them in five
subjects and prints the names of the students who have obtained highest and second highest
marks subject wise.
Enter the marks of student 1: 90 98 76 55 52
Enter the marks of student 2: 30 45 67 89 2
Enter the marks of student 3: 32 67 86 44 45
Enter the marks of student 4: 23 4 23 56 87
Enter the marks of student 5: 12 78 09 87 54
Enter the marks of student 6: 91 45 67 86 21
Enter the marks of student 7: 34 45 65 76 98
Enter the marks of student 8: 23 56 12 23 34
Enter the marks of student 9: 09 97 87 65 43
Enter the marks of student 10: 65 85 46 3 42

Output:
Roll number of students with highest and second highest marks in subject 1: 6 1
Roll number of students with highest and second highest marks in subject 2: 1 9
Roll number of students with highest and second highest marks in subject 3: 9 3
Roll number of students with highest and second highest marks in subject 4: 2 5
Roll number of students with highest and second highest marks in subject 5: 7 4

8. Write a program which takes some numbers and computes the standard deviation of them.

Output:

Enter the number of values: 5

Enter the values: 34 76 98 37 50

Standard Deviation: 24.49489

You might also like