C Programming Basic - Exercises, Practice, Solution - W3resource
C Programming Basic - Exercises, Practice, Solution - W3resource
Expected Output:
3. Write a C program to print a block F using the hash (#), where the F has a height of six characters and width of five and
four characters. And also print a very large 'C'.
Expected Output:
######
#
#
#####
#
#
#
######
## ##
#
#
#
#
#
## ##
######
5. Write a C program to compute the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches.
Expected Output:
Perimeter of the rectangle = 24 inches
Area of the rectangle = 35 square inches
Click me to see the solution
6. Write a C program to compute the perimeter and area of a circle with a given radius.
Expected Output:
Perimeter of the Circle = 37.680000 inches
Area of the Circle = 113.040001 square inches
Click me to see the solution
8. Write a C program to convert specified days into years, weeks and days.
Note: Ignore leap year.
Test Data :
Number of days : 1329
Expected Output :
Years: 3
Weeks: 33
Days: 3
Click me to see the solution
9. Write a C program that accepts two integers from the user and calculates the sum of the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 38
Expected Output:
Sum of the above two integers = 63
Click me to see the solution
10. Write a C program that accepts two integers from the user and calculates the product of the two integers.
Test Data :
Input the first integer: 25
Input the second integer: 15
Expected Output:
Product of the above two integers = 375
Click me to see the solution
11. Write a C program that accepts two item's weight and number of purchases (floating point values) and calculates their
average value.
Test Data :
Weight - Item1: 15
No. of item1: 5
Weight - Item2: 25
No. of item2: 4
Expected Output:
Average Value = 19.444444
Click me to see the solution
12. Write a C program that accepts an employee's ID, total worked hours in a month and the amount he received per hour.
Print the ID and salary (with two decimal places) of the employee for a particular month.
Test Data :
Input the Employees ID(Max. 10 chars): 0342
Input the working hrs: 8
Salary amount/hr: 15000
Expected Output:
Employees ID = 0342
Salary = U$ 120000.00
Click me to see the solution
13. Write a C program that accepts three integers and finds the maximum of three.
Test Data :
Input the first integer: 25
Input the second integer: 35
Input the third integer: 15
Expected Output:
Maximum value of three integers: 35
Click me to see the solution
14. Write a C program to calculate a bike’s average consumption from the given total distance (integer value) travelled (in
km) and spent fuel (in litters, float number – 2 decimal points).
Test Data :
Input total distance in km: 350
Input total fuel spent in liters: 5
Expected Output:
Average consumption (km/lt) 70.000
Click me to see the solution
16. Write a C program to read an amount (integer value) and break the amount into the smallest possible number of bank
notes.
Test Data :
Input the amount: 375
Expected Output:
There are:
3 Note(s) of 100.00
1 Note(s) of 50.00
1 Note(s) of 20.00
0 Note(s) of 10.00
1 Note(s) of 5.00
0 Note(s) of 2.00
0 Note(s) of 1.00
Click me to see the solution
17. Write a C program to convert a given integer (in seconds) to hours, minutes and seconds.
Test Data :
Input seconds: 25300
Expected Output:
There are:
H:M:S - 7:1:40
Click me to see the solution
18. Write a C program to convert a given integer (in days) to years, months and days, assuming that all months have 30 days
and all years have 365 days.
Test Data :
Input no. of days: 2535
Expected Output:
6 Year(s)
11 Month(s)
15 Day(s)
Click me to see the solution
19. Write a C program that accepts 4 integers p, q, r, s from the user where q, r and s are positive and p is even. If q is
greater than r and s is greater than p and if the sum of r and s is greater than the sum of p and q print "Correct values",
otherwise print "Wrong values".
Test Data :
Input the second integer: 35
Input the third integer: 15
Input the fourth integer: 46
Expected Output:
Wrong values
Click me to see the solution
20. Write a C program to print the roots of Bhaskara’s formula from the given three floating numbers. Display a message if it
is not possible to find the roots.
Test Data :
Input the first number(a): 25
Input the second number(b): 35
Input the third number(c): 12
Expected Output:
Root1 = -0.60000
Root2 = -0.80000
Click me to see the solution
21. Write a C program that reads an integer and checks the specified range to which it belongs. Print an error message if the
number is negative and greater than 80.
Test Data :
Input an integer: 15
Expected Output:
Range [0, 20]
Click me to see the solution
22. Write a C program that reads 5 numbers and sums all odd values between them.
Test Data :
Input the first number: 11
Input the second number: 17
Input the third number: 13
Input the fourth number: 12
Input the fifth number: 5
Expected Output:
Sum of all odd values: 46
Click me to see the solution
23. Write a C program that reads three floating-point values and checks if it is possible to make a triangle with them.
Determine the perimeter of the triangle if the given values are valid.
Test Data :
Input the first number: 25
Input the second number: 15
Input the third number: 35
Expected Output:
Perimeter = 75.0
Click me to see the solution
24. Write a C program that reads two integers and checks whether they are multiplied or not.
Test Data :
Input the first number: 5
Input the second number: 15
Expected Output:
Multiplied!
Click me to see the solution
25. Write a C program that reads an integer between 1 and 12 and prints the month of the year in English.
Test Data :
Input a number between 1 to 12 to get the month name: 8
Expected Output:
August
Click me to see the solution
26. Write a C program that prints all even numbers between 1 and 50 (inclusive).
Test Data :
Even numbers between 1 to 50 (inclusive):
Expected Output:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
Click me to see the solution
27. Write a C program that reads 5 numbers and counts the number of positive numbers and negative numbers.
Test Data :
Input the first number: 5
Input the second number: -4
Input the third number: 10
Input the fourth number: 15
Input the fifth number: -1
Expected Output:
Number of positive numbers: 3
Number of negative numbers: 2
Click me to see the solution
28. Write a C program that reads 5 numbers, counts the number of positive numbers, and prints out the average of all
positive values.
Test Data :
Input the first number: 5
Input the second number: 8
Input the third number: 10
Input the fourth number: -5
Input the fifth number: 25
Expected Output:
Number of positive numbers: 4
Average value of the said positive numbers: 12.00
Click me to see the solution
29. Write a C program that read 5 numbers and sum of all odd values between them.
Test Data :
Input the first number: 5
Input the second number: 7
Input the third number: 9
Input the fourth number: 10
Input the fifth number: 13
Expected Output:
Sum of all odd values: 34
Click me to see the solution
30. Write a C program to find and print the square of all the even values from 1 to a specified value.
Test Data :
List of square of each one of the even values from 1 to a 4 :
Expected Output:
2^2 = 4
4^2 = 16
Click me to see the solution
31. Write a C program to check whether a given integer is positive even, negative even, positive odd or negative odd. Print
even if the number is 0.
Test Data :
Input an integer: 13
Expected Output:
Positive Odd
Click me to see the solution
32. Write a C program to print all numbers between 1 and 100 which are divided by a specified number and the remainder
will be 3.
Test Data :
Input an integer: 25
Expected Output:
3
28
53
78
Click me to see the solution
33. Write a C program that accepts some integers from the user and finds the highest value and the input position.
Test Data :
Input 5 integers:
5
7
15
23
45
Expected Output:
Highest value: 45
Position: 5
Click me to see the solution
34. Write a C program to compute the sum of consecutive odd numbers from a given pair of integers.
Test Data :
Input a pair of numbers (for example 10,2):
Input first number of the pair: 10
Input second number of the pair: 2
Expected Output:
List of odd numbers: 3
5
7
9
Sum=24
Click me to see the solution
35. Write a C program to check if two numbers in a pair are in ascending order or descending order.
Test Data :
Input a pair of numbers (for example 10,2 : 2,10):
Input first number of the pair: 10
Expected Output:
Input second number of the pair: 2
The pair is in descending order!
Click me to see the solution
36. Write a C program to read a password until it is valid. For wrong password print "Incorrect password" and for correct
password print, "Correct password" and quit the program. The correct password is 1234.
Test Data :
Input the password: 1234
Expected Output:
Correct password
Click me to see the solution
37. Write a C program to read the coordinates (x, y) (in the Cartesian system) and find the quadrant to which it belongs
(Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV).
Note: A Cartesian coordinate system is a coordinate system that specifies each point uniquely in a plane by a pair of
numerical coordinates.
These are often numbered from 1st to 4th and denoted by Roman numerals: I (where the signs of the (x,y) coordinates are
I(+,+), II (−,+), III (−,−), and IV (+,−).
Test Data :
Input the Coordinate(x,y):
x: 25
y: 15
Expected Output:
Quadrant-I(+,+)
Click me to see the solution
38. Write a program that reads two numbers and divides the first number by the second number. If division is not possible
print "Division is not possible".
Test Data :
Input two numbers:
x: 25
y: 5
Expected Output: 5.0
Click me to see the solution
39. Write a C program to calculate the sum of all numbers not divisible by 17 between two given integer numbers.
Test Data :
Input the first integer: 50 Input the second integer: 99
Expected Output:
Sum: 3521
Click me to see the solution
40. Write a C program that finds all integer numbers that divide by 7 and have a remainder of 2 or 3 between two given
integers.
Test Data :
Input the first integer: 25
Input the second integer: 45
Expected Output:
30
31
37
38
44
Click me to see the solution
41. Write a C program to print 3 numbers on a line, starting with 1 and printing n lines. Accept the number of lines (n, integer)
from the user.
Test Data :
Input number of lines: 5
Expected Output:
123
456
789
10 11 12
13 14 15
Click me to see the solution
42. Write a C program to print a number, its square and cube, starting with 1 and printing n lines. Accept the number of lines
(n, integer) from the user.
Test Data :
Input number of lines: 5
Expected Output:
111
248
3 9 27
4 16 64
5 25 125
Click me to see the solution
43. Write a C program that reads two integers p and q, prints p number of lines in a sequence of 1 to b in a line.
Test Data :
Input number of lines: 5
Number of characters in a line: 6
Expected Output:
123456
7 8 9 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
Click me to see the solution
44. Write a C program to calculate the average mathematics marks of some students. Input 0 (excluding to calculate the
average) or a negative value to terminate the input process.
Test Data :
Input Mathematics marks (0 to terminate): 10
15
20
25
0
Expected Output:
Average marks in Mathematics: 17.50
Click me to see the solution
45. Write a C program to calculate the value of S where S = 1 + 1/2 + 1/3 + … + 1/50.
Expected Output:
Value of S: 4.50
Click me to see the solution
46. Write a C program to calculate the value of S where S = 1 + 3/2 + 5/4 + 7/8.
Expected Output:
Value of series: 4.62
Click me to see the solution
48. Write a C program that reads and prints the elements of an array of length 7. Before printing, replace every negative
number, zero, with 100.
Test Data:
Input the 5 members of the array:
25
45
35
65
15
Expected Output:
Array values are:
n[0] = 25
n[1] = 45
n[2] = 35
n[3] = 65
n[4] = 15
Click me to see the solution
49. Write a C program to read and print the elements of an array with length 7. Before printing, insert the triple of the previous
position, starting from the second position.
For example, if the first number is 2, the array numbers must be 2, 6, 18, 54 and 162
Test Data:
Input the first number of the array: 5
Expected Output:
n[0] = 5
n[1] = 15
n[2] = 45
n[3] = 135
n[4] = 405
Click me to see the solution
50. Write a C program to read an array of length 5 and print the position and value of the array elements of value less than 5.
Test Data:
Input the 5 members of the array:
15
25
4
35
40
Expected Output:
A[2] = 4.0
Click me to see the solution
51. Write a C program to read an array of length 6, change the first element by the last, the second element by the fifth and
the third element by the fourth. Print the elements of the modified array.
Test Data:
Input the 5 members of the array:
15
20
25
30
35
Expected Output:
array_n[0] = 35
array_n[1] = 30
array_n[2] = 25
array_n[3] = 20
array_n[4] = 15
Click me to see the solution
52. Write a C program to read an array of length 6 and find the smallest element and its position.
Test Data:
Input the length of the array: 5 Input the array elements:
25
35
20
14
45
Expected Output:
Smallest Value: 14
Position of the element: 3
Click me to see the solution
53. Write a C program that accepts the principle, rate of interest, and time and calculates simple interest.
Test Data:
Input Data: p = 10000, r = 10% , t = 12 year
Expected Output:
Input principle, Rate of interest & time to find simple interest:
Simple interest = 12000
Click me to see the solution
54. Write a C program that accepts a distance in centimeters and prints the corresponding value in inches.
Test Data:
Input Data: 500cms
Input the distance in cm:
Distance of 500.00 cms is = 196.85 inches
Click me to see the solution
55. Write a C program that swaps two numbers without using a third variable.
Input value for x & y:
Before swapping the value of x & y: 5 7
After swapping the value of x & y: 7 5
Click me to see the solution
56. Write a C program to shift given data by two bits to the left.
Input value : 2
Read the integer from keyboard-
Integer value = 2
The left shifted data is = 16
Click me to see the solution
58. Write a C program that accepts 4 real numbers from the keyboard and prints out the difference between the maximum
and minimum values of these four numbers.
Input four numbers: 1.54 1.236 1.3625 1.002
Difference is 0.5380
Click me to see the solution
59. Write a C program to display the sum of series 1 + 1/2 + 1/3 + ………. + 1/n.
Input any number: 1 + 1/0
Sum = 1/0
Click me to see the solution
60. Write a C program to create enumerated data types for 7 days and display their values in integer constants.
Sun = 0
Mon = 1
Tue = 2
Wed = 3
Thu = 4
Fri = 5
Sat = 6
Click me to see the solution
61. Write a C program that accepts a real number x and prints out the corresponding value of sin(1/x) using 4-decimal places.
Input value of x: .6235
Value of sin(1/x) is 0.9995
Click me to see the solution
62. Write a C program that accepts a positive integer less than 500 and prints out the sum of the digits of this number.
Input a positive number less than 500:
Sum of the digits of 347 is 14
Click me to see the solution
63. Write a C program that accepts a positive integer n less than 100 from the user. It prints out the sum of 14 + 24 + 44 +
74 + 114 + • • • + m4. In this case, m is less than or equal to n. Print an appropriate message.
Input a positive number less than 100: 68
Sum of the series is 37361622
Click me to see the solution
64. Write a C program that accepts integers from the user until a zero or a negative number, displays the number of positive
values, the minimum value, the maximum value, and the average value.
Input a positive integer:
Input next positive integer: 15
Input next positive integer: 25
Input next positive integer: 37
Input next positive integer: 43
Number of positive values entered is 4
Maximum value entered is 43
Minimum value entered is 15
Average value is 30.0000
Click me to see the solution
65. Write a C program that prints out the prime numbers between 1 and 200. The output should be such that each row
contains a maximum of 20 prime numbers.
Expected output:
The prime numbers between 1 and 199 are:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197
Click me to see the solution
66. Write a C program that generates 50 random numbers between -0.5 and 0.5 and writes them to the file rand.dat. The first
line of ran.dat contains the number of random numbers, while the next 50 lines contain 50 random numbers.
50
-0.4215
0.2620
0.3065
-0.0485
.... 0.3980
0.1750
0.4780
-0.2915
0.0715
0.3565
Click me to see the solution
67. Write a C program to evaluate the equation y=xn when n is a non-negative integer.
Input the values of x and n: 256
x=256.000000; n=0;
x to power n=1.000000
Click me to see the solution
68. Write a C program that prints the powers of 2 table for the powers 0 to 10, both positive and negative.
=======================================
n 2 to power n 2 to power -n
=======================================
0 1 1.000000000000
1 2 0.500000000000
2 4 0.250000000000
3 8 0.125000000000
4 16 0.062500000000
5 32 0.031250000000
6 64 0.015625000000
7 128 0.007812500000
8 256 0.003906250000
9 512 0.001953125000
10 1024 0.000976562500
======================================
Click me to see the solution
70. Write a C program to print the alphabet set in decimal and character form.
[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] [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]
Click me to see the solution
71. Write a C program to copy a given string into another and count the number of characters copied.
Input a string
Original string: w3resource
Number of characters = 10
Click me to see the solution
73. Write a C program that reads two integers and checks whether the first integer is a multiple of the second integer.
Sample Input: 9 3
Sample Output:
Input the first integer : Input the second integer:
9 is a multiple of 3.
Click me to see the solution
74. Write a C program to display the integer equivalents of letters (a-z, A-Z).
Sample Output:
List of integer equivalents of letters (a-z, A-Z).
==================================================
97 98 99 100 101 102
103 104 105 106 107 108
109 110 111 112 113 114
115 116 117 118 119 120
121 122 32 65 66 67
68 69 70 71 72 73
74 75 76 77 78 79
80 81 82 83 84 85
86 87 88 89 90
Click me to see the solution
75. Write a C program that accepts a seven-digit number, separates the number into its individual digits, and prints the digits
separated from one another by two spaces each.
Sample Input: 2345678
Input a seven digit number:
Output: 2 3 4 5 6 7 8
Click me to see the solution
76. Write a C program to calculate and print the squares and cubes of the numbers from 0 to 20. It uses tabs to display them
in a table of values.
Sample Output:
Number Square Cube
=========================
000
111
248
3 9 27
.....
18 324 5832
19 361 6859
20 400 8000
Click me to see the solution
77. Write a C program that accepts principal amount, rate of interest and days for a loan and calculates the simple interest for
the loan, using the following formula.
interest = principal * rate * days / 365.
Sample Input:
10000
.1
365
0
Sample Output:
Input loan amount (0 to quit): Input interest rate: Input term of the loan in days: The interest amount is $1000.00
Input loan principal_amt (0 to quit):
Click me to see the solution
78. Write a C program to demonstrate the difference between predecrementing and postdecrementing using the decrement
operator --.
Sample Output:
Predecrementing:
x = 10
x-- = 10
x=9
Click me to see the solution
79. Write a C program using looping to produce the following table of values.
Sample Output:
80. Write a C program that reads the side (side sizes between 1 and 10 ) of a square and prints square using hash (#)
character.
Sample Input: 10
Sample Output:
81. Write a C program that reads the side (side sizes between 1 and 10 ) of a square and prints a hollow square using the
hash (#) character.
Sample Input: 10
Sample Output:
82. Write a C program that reads a five-digit integer and determines whether or not it's a palindrome.
Sample Input: 33333
Sample Output:
83. Write a C program that reads an integer (7 digits or fewer) and counts the number of 3s in the given number.
Sample Input: 538453
Sample Output:
84. Write a C program to calculate and print the average of some integers. Accept all the values preceding 888.
Sample Input:12
15
24
888
Sample Output:
85. Write a C program to print a table of all the Roman numeral equivalents of decimal numbers in the range 1 to 50.
Sample Output:
Decimal Roman
number numeral
-------------------
1 I
2 II
3 III
4 IV
.....
98 LXXXXVIII
99 LXXXXIX
100 C
86. Write a C program to display the sizes and ranges for each of C's data types.
Sample Output:
Type Bytes
--------------------------------
char 1
int8_t 1
unsigned char 1
uint8_t 1
short 2
int16_t 2
uint16t 2
int 4
unsigned 4
long 8
unsigned long 8
int32_t 4
uint32_t 4
long long 8
int64_t 8
unsigned long long 8
uint64_t 8
float 4
double 8
long double 16
_Bool 1
------------------------------------------------------------
int8_t -128 127
int16_t -32768 32767
int32_t -2147483648 2147483647
int64_t -9223372036854775808 9223372036854775807
uint8_t 0 255
uint16_t 0 65535
uint32_t 0 4294967295
uint64_t 0 18446744073709551615
============================================================
------------------------------------------------------------
float 1.175494e-38 3.402823e+38
double 2.225074e-308 1.797693e+308
long double 3.362103e-4932 1.189731e+4932
88. Write a C program to create an extended ASCII table. Print the ASCII values 32 through 255.
Sample Output:
|---------------------------------------------------------------------------------------------------------|
|extended ASCII table - excluding control characters |
| Ch Dec Hex | Ch Dec Hex | Ch Dec Hex | Ch Dec Hex | Ch Dec Hex | Ch Dec Hex | Ch Dec Hex |
|----------------|----------------|-------------|--------------|--------------|-------------|-------------|
| har 32 0x20 | @har 64 0x40 | ` 96 0x60 | � 128 0x80 | � 160 0xa0 | � 192 0xc0 | � 224 0xe0 |
| !har 33 0x21 | Ahar 65 0x41 | a 97 0x61 | � 129 0x81 | � 161 0xa1 | � 193 0xc1 | � 225 0xe1 |
| "har 34 0x22 | Bhar 66 0x42 | b 98 0x62 | � 130 0x82 | � 162 0xa2 | � 194 0xc2 | � 226 0xe2 |
| #har 35 0x23 | Char 67 0x43 | c 99 0x63 | � 131 0x83 | � 163 0xa3 | � 195 0xc3 | � 227 0xe3 |
| $har 36 0x24 | Dhar 68 0x44 | d 100 0x64 | � 132 0x84 | � 164 0xa4 | � 196 0xc4 | � 228 0xe4 |
| %har 37 0x25 | Ehar 69 0x45 | e 101 0x65 | � 133 0x85 | � 165 0xa5 | � 197 0xc5 | � 229 0xe5 |
| &har 38 0x26 | Fhar 70 0x46 | f 102 0x66 | � 134 0x86 | � 166 0xa6 | � 198 0xc6 | � 230 0xe6 |
| 'har 39 0x27 | Ghar 71 0x47 | g 103 0x67 | � 135 0x87 | � 167 0xa7 | � 199 0xc7 | � 231 0xe7 |
| (har 40 0x28 | Hhar 72 0x48 | h 104 0x68 | � 136 0x88 | � 168 0xa8 | � 200 0xc8 | � 232 0xe8 |
| )har 41 0x29 | Ihar 73 0x49 | i 105 0x69 | � 137 0x89 | � 169 0xa9 | � 201 0xc9 | � 233 0xe9 |
| *har 42 0x2a | Jhar 74 0x4a | j 106 0x6a | � 138 0x8a | � 170 0xaa | � 202 0xca | � 234 0xea |
| +har 43 0x2b | Khar 75 0x4b | k 107 0x6b | � 139 0x8b | � 171 0xab | � 203 0xcb | � 235 0xeb |
| ,har 44 0x2c | Lhar 76 0x4c | l 108 0x6c | � 140 0x8c | � 172 0xac | � 204 0xcc | � 236 0xec |
| -har 45 0x2d | Mhar 77 0x4d | m 109 0x6d | � 141 0x8d | � 173 0xad | � 205 0xcd | � 237 0xed |
| .har 46 0x2e | Nhar 78 0x4e | n 110 0x6e | � 142 0x8e | � 174 0xae | � 206 0xce | � 238 0xee |
| /har 47 0x2f | Ohar 79 0x4f | o 111 0x6f | � 143 0x8f | � 175 0xaf | � 207 0xcf | � 239 0xef |
| 0har 48 0x30 | Phar 80 0x50 | p 112 0x70 | � 144 0x90 | � 176 0xb0 | � 208 0xd0 | � 240 0xf0 |
| 1har 49 0x31 | Qhar 81 0x51 | q 113 0x71 | � 145 0x91 | � 177 0xb1 | � 209 0xd1 | � 241 0xf1 |
| 2har 50 0x32 | Rhar 82 0x52 | r 114 0x72 | � 146 0x92 | � 178 0xb2 | � 210 0xd2 | � 242 0xf2 |
| 3har 51 0x33 | Shar 83 0x53 | s 115 0x73 | � 147 0x93 | � 179 0xb3 | � 211 0xd3 | � 243 0xf3 |
| 4har 52 0x34 | Thar 84 0x54 | t 116 0x74 | � 148 0x94 | � 180 0xb4 | � 212 0xd4 | � 244 0xf4 |
| 5har 53 0x35 | Uhar 85 0x55 | u 117 0x75 | � 149 0x95 | � 181 0xb5 | � 213 0xd5 | � 245 0xf5 |
| 6har 54 0x36 | Vhar 86 0x56 | v 118 0x76 | � 150 0x96 | � 182 0xb6 | � 214 0xd6 | � 246 0xf6 |
| 7har 55 0x37 | Whar 87 0x57 | w 119 0x77 | � 151 0x97 | � 183 0xb7 | � 215 0xd7 | � 247 0xf7 |
| 8har 56 0x38 | Xhar 88 0x58 | x 120 0x78 | � 152 0x98 | � 184 0xb8 | � 216 0xd8 | � 248 0xf8 |
| 9har 57 0x39 | Yhar 89 0x59 | y 121 0x79 | � 153 0x99 | � 185 0xb9 | � 217 0xd9 | � 249 0xf9 |
| :har 58 0x3a | Zhar 90 0x5a | z 122 0x7a | � 154 0x9a | � 186 0xba | � 218 0xda | � 250 0xfa |
| ;har 59 0x3b | [har 91 0x5b | { 123 0x7b | � 155 0x9b | � 187 0xbb | � 219 0xdb | � 251 0xfb |
| <har 60 0x3c | \har 92 0x5c | | 124 0x7c | � 156 0x9c | � 188 0xbc | � 220 0xdc | � 252 0xfc |
| =har 61 0x3d | ]har 93 0x5d | } 125 0x7d | � 157 0x9d | � 189 0xbd | � 221 0xdd | � 253 0xfd |
| >har 62 0x3e | ^har 94 0x5e | ~ 126 0x7e | � 158 0x9e | � 190 0xbe | � 222 0xde | � 254 0xfe |
| ?har 63 0x3f | _har 95 0x5f |DEL 127 0x7f | � 159 0x9f | � 191 0xbf | � 223 0xdf | � 255 0xff |
89. Write a C programming to calculate (x + y + z) for each pair of integers x, y and z where -2^31 <= x, y, z<= 2^31-1.
Sample Output:
Result: 140733606875472
Click me to see the solution
90. Write a C program to find all prime palindromes in the range of two given numbers x and y (5 <= x<y<= 1000,000,000).
A number is called a prime palindrome if the number is both a prime number and a palindrome.
Sample Output:
91. Write a C program to find the angle between (12:00 to 11:59) the hour hand and the minute hand of a clock. The hour
hand and the minute hand are always between 0 and 180 degrees.
For example, when it's 12 o'clock, the angle of the two hands is 0 while 3:00 is 45 degrees and 6:00 is 180 degrees.
Sample Output:
92. Write a C program to find the last non-zero digit of the factorial of a given positive integer.
For example for 5!, the output will be "2" because 5! = 120, and 2 is the last nonzero digit of 120
Sample Output:
93. Write a C program to check if a given number is nearly prime number or not.
Nearly prime numbers are a positive integer which is equal to the product of two prime numbers.
Sample Output:
94. Write a C program to calculate body mass index and display the grade.
Sample Output:
Grade: Under
95. Write a C program to print the corresponding Fahrenheit to Celsius and Celsius to Fahrenheit.
Both cases initial tempratue = 00, maximum temperature = 1500 and step 100
Sample Output:
Celsius to Fahrenheit
---------------------
Celsius Fahrenheit
0.0 32.0
10.0 50.0
20.0 68.0
30.0 86.0
....
120.0 248.0
130.0 266.0
140.0 284.0
150.0 302.0
Fahrenheit to Celsius
---------------------
Fahrenheit Celsius
0.0 -17.8
10.0 -12.2
20.0 -6.7
30.0 -1.1
40.0 4.4
50.0 10.0
...
120.0 48.9
130.0 54.4
140.0 60.0
150.0 65.6
96. Write a C program to count blanks, tabs, and newlines in input text.
Sample Output:
97. Write a C program that accepts a string and counts the number of characters, words and lines.
Sample Output:
Input a string and get number of charcters, words and lines:
The quick brown fox jumps over the lazy dog
^Z
Number of Characters = 44
Number of words = 9
Number of lines = 1
98. Write a C program that accepts some text from the user and prints each word of that text on a separate line.
Sample Output:
99. Write a C program that takes some integer values from the user and prints a histogram.
Sample Output:
100. Write a C program to convert a currency value (floating point with two decimal places) to the number of coins and notes.
Sample Output:
Input the currency value (floating point with two decimal places):
10357.75
Currency Notes:
100 number of Note(s): 103
50 number of Note(s): 1
5 number of Note(s): 1
2 number of Note(s): 1
Currency Coins:
.50 number of Coin(s): 1
.25 number of Coin(s): 1
101. There are three given ranges. Write a C program that reads a floating-point number and finds the range where it
belongs from four given ranges.
Sample Output:
Input a number: 87
Range (80,100]
Input 3 integers: 17
-5
25
---------------------------
Original numbers: 17, -5, 25
Sorted numbers: -5, 17, 25
103. Write a C program that takes two integers and tests whether they are multiplied or not.
In science, a multiple is the product of any quantity and an integer. In other words, for the quantities a and b, we say that b is
a multiple of a if b = na for some integer n, which is called the multiplier. If a is not zero, this is equivalent to saying that b/a is
an integer.
Sample Output:
104. Write a C program that reads the item's price and creates a revised price for the item, based on the item price table.
Sample Output:
Input 7 numbers(int/float):
25
35.75
15
-3.5
40
35
16
106. Write a C program that accepts 7 integer values and counts the even, odd, positive and negative values.
Sample Output:
Input 7 integers:
10
12
15
-15
26
35
17
108. Write a C program that reads two integer values and calculates the sum of all odd numbers between them.
Sample Output:
109. Write a C program to find and print the square of each even and odd value between 1 and a given number (4 < n < 101).
Sample Output:
Input a number(integer): 15
110. Write a C program to find the odd, even, positive and negative numbers from a given number (integer) and print a
message 'Number is positive odd' or 'Number is negative odd' or 'Number is positive even' or 'Number is negative even'. If
the number is 0 print "Zero".
Sample Output:
111. Write a C program that accepts an integer from the user and divides all numbers between 1 and 100. Print those
numbers where the remainder value is 3.
Sample Output:
Remainder value is 3 after divide all numbers between 1 and 100 by 65:
3
68
112. Write a C program that reads seven integer values from the user and finds the highest value and its position.
Sample Output:
Maximum value: 35
Position: 6
113. Write a C program to create and print the sequence of the following example.
Sample Output:
a=1 b=100
a=6 b=90
a=11 b=80
a=16 b=70
a=21 b=60
a=26 b=50
a=31 b=40
a=36 b=30
a=41 b=20
a=46 b=10
a=51 b=0
Sample Output:
115. Write a C program that accepts a pair of numbers from the user and prints the sequence from the lowest to the highest
number. Also, print the average value of the sequence.
Sample Output:
116. Write a C program that accepts a pair of numbers from the user and prints "Ascending order" if the two numbers are in
ascending order, otherwise prints, "Descending order".
Sample Output:
Sample Output:
117. Write a C program that reads two integers and divides the first number by second, print the result of this division with
two digits after the decimal point and prints “Division not possible..!” if the division is not possible.
Sample Output:
118. Write a C program that reads five subject marks (0-100) of a student and calculates the average of these marks.
Sample Output:
119. Write a C program to calculate the sum of all numbers between two given numbers (inclusive) not divisible by 7.
Sample Output:
Sample Output:
Input two numbers(integer):
6
36
Sum of all numbers between said numbers (inclusive) not divisible by 7:
546
120. Write a C program to print a sequence from 1 to a given (integer) number, inserting a comma between these numbers.
There will be no comma after the last character.
Sample Output:
Input a number(integer):
25
Sequence:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25
121. Write a C program that reads an integer and finds all the divisors of the said integer.
Sample Output:
122. Write a C program that reads two integers m, n and computes the sum of n even numbers starting from m.
Sample Output:
123. Write a C program that reads two integers m, n and computes the sum of n odd numbers starting from m.
Sample Output:
124. Write a C program that reads an array of integers (length 7), replaces every negative or null element with 1 and prints
the array elements.
Sample Output:
Array elements:
array_nums[0] = 15
array_nums[1] = 12
array_nums[2] = 1
array_nums[3] = 25
array_nums[4] = 1
array_nums[5] = 27
array_nums[6] = 53
125. Write a C program that reads an array of integers (length 7), and replaces the first element of the array by a given
number and replaces each subsequent position of the array by the double value of the previous.
Sample Output:
Array elements:
array_nums[0] = 5
array_nums[1] = 10
array_nums[2] = 20
array_nums[3] = 40
array_nums[4] = 80
array_nums[5] = 160
array_nums[6] = 320
126. Write a C program that reads an array (length 7) and prints all array positions that store a value less than or equal to 0.
Sample Output:
Input 7 array elements:
15
23
37
65
20
-7
65
127. Write a C program that reads an array of integers (length 8), replaces the 1st element with the 8th, the 2nd with the
7th and so on. Print the final array.
Sample Output:
Modified array:
array_nums[0] = 65
array_nums[1] = 60
array_nums[2] = 45
array_nums[3] = 29
array_nums[4] = -5
array_nums[5] = 17
array_nums[6] = 35
array_nums[7] = 25
128. Write a C program that reads an array of integers (length 10), fills it with numbers from o to a (given number) n – 1
repeatedly, where 2 ≤ n ≤ 10.
Sample Output:
129. Write a C program that reads an array (length 10), and replaces the first element of the array by a given number and
replaces each subsequent position of the array by one-third the value of the previous.
Sample Output:
130. Write a C program to create an array of length n and fill the array elements with integer values. Find the smallest value
and its position in the array.
Sample Output:
Input a number:
35
Array elements:
array_nums[0] = 35.0000
array_nums[1] = 11.6667
array_nums[2] = 3.8889
array_nums[3] = 1.2963
array_nums[4] = 0.4321
array_nums[5] = 0.1440
array_nums[6] = 0.0480
array_nums[7] = 0.0160
array_nums[8] = 0.0053
array_nums[9] = 0.0018
131.Write a C program that accepts two strings and checks whether the second string is present in the last part of the first
string.
Sample Output:
Input the first string:
abcdef
Input the second string:
ef
Is second string present in the last part of the first string?
Present!
132. Write a C program to find the heights of the top three buildings in descending order from eight given buildings.
Input:
0 <= height of building (integer) <= 10,000
Sample Output:
133. Write a C program to calculate the sum of two given integers and count the number of digits in the sum value.
Sample Output:
Input two integer values:
68
75
134. Write a C program to check whether the three given lengths (integers) of three sides of a triangle form a right triangle or
not. Print "Yes" if the given sides form a right triangle otherwise print "No".
Input:
Integers separated by a single space.
1 <= length of the side <= 1,000
Sample Output:
135. Write a C program that reads an integer n and finds the number of combinations of a, b, c and d (0 ≤ a, b, c, d ≤ 9)
where (a + b + c + d) will be equal to n.
Input:
n (1 <= n <= 50)
Sample Output:
Input a number:
5
a + b + c + d = n
0, 0, 0, 5
0, 0, 1, 4
....
4, 0, 1, 0
4, 1, 0, 0
5, 0, 0, 0
136. Write a C program to find prime numbers that are less than or equal to a given integer.
Input:
n (1 <= n <= 999,999)
Sample Output:
Input a number:
123
Number of prime numbers which are less than or equal to 123
30
137. Write a C program to check if a point (x, y) is within a triangle or not. Three points make up a triangle.
Input:
x1,y1,x2,y2,x3,y3,xp,yp separated by a single space
Sample Output:
138.Write a C program to test whether two lines are parallel or not. The four points are P(x1, y1), Q(x2, y2), R(x3, y3) and
S(x4, y4), check PQ and RS are parallel are not.
Input:
−100 <= x1, y1, x2, y2, x3, y3, x4, y4 <= 100
Each value is a real number with at most 5 digits after the decimal point.
Sample Output:
Input P(x1,y1):
5
7
Input P(x2,y2):
3
6
Input P(x3,y3):
8
9
Input P(x4,y4):
5
6
Sample Output:
140. Write a C program that reads a sequence of integers and finds the element that occurs most frequently.
Sample Output:
141. Write a C program that reads n digits (given) chosen from 0 to 9 and prints the number of combinations where the sum
of the digits equals another given number (s). Do not use the same digits in a combination.
For example, the combinations where n = 3 and s = 6 are as follows:
1+2+3=6
0+1+5=6
0+2+4=6
Sample Output:
142. Write a C program that reads the two adjoining sides and the diagonal of a parallelogram and checks whether the
parallelogram is a rectangle or a rhombus.
Input:
Two adjoined sides and the diagonal.
1 <= ai, bi, ci <= 1000, ai + bi > ci
Sample Output:
Input two adjoined sides of the parallelogram:
3
4
This is a rectangle.
Sample Output:
This is a rhombus.
143. Write a C program to find the difference between the largest integer and the smallest integer, which are created by 8
numbers from 0 to 9. The number that can be rearranged shall start with 0 as in 00135668.
Input:
Data is a sequence of 8 numbers (digits from 0 to 9).
Output:
The difference between the largest integer and the smallest integer.
Sample Output:
144. Write a C program to create the maximum number of regions obtained by drawing n given straight lines.
Input:
(1 ≤ n ≤ 10,000).
Sample Output:
145. Write a C program to sum all numerical values (positive integers) embedded in a sentence.
Input:
Sentences with positive integers are given over multiple lines. Each line is a character string containing one-byte
alphanumeric characters, symbols, spaces, or an empty line. However the input is 80 characters or less per line and the sum
is 10,000 or less.
Sample Output:
Sample Output:
147. Write a C program to find the number of combinations that satisfy p + q + r + s = n where n is a given number <= 4000
and p, q, r, s are between 0 and 1000.
Sample Output:
148. Write a C program, which adds up columns and rows of given table as shown in the following figure.
Input:
n (the size of row and column of the given table)
1st row of the table
2nd row of the table
:
:
n th row of the table
The input ends with a line consisting of a single 0.
Sample Output:
Result:
25 69 51 26 171
68 35 29 54 186
54 57 45 63 219
61 68 47 59 235
208 229 172 202 811
149. Write a C program that reads a list of pairs of a word and a page number, and prints the word and a list of the
corresponding page numbers.
Input:
word page_number
Output:
word
a_list_of_the_page_number
word
a_list_of_the_Page_number.
Sample Output:
Sample Output:
Sample Output:
Sample Output: