C Assignment
C Assignment
txpectud Output:
Name Armit Jain
DOB :July 14, 1975
Mobile 91 9999999999
10. V.ite aC prog 1m to print block F usig hash (), where the Fn height of six characters and width of
five and four characters
Expected Output
13. Write a i program to tonpute the perimeter and area of a rectang vwith a he-ght of 7 inches. and widtn
of S in hes
Expecd Output:
Perim tr d the rectangle* 4 inces
Area h e rectangle r *5 S0are i n h e s
4.Write aC program to u ute the perimeter and ares of a cirete with a radius of 6 inches.
Expe ted Output:
UNIVERSAL INFORMATIc
www.Uversalinformatics.comE-mail:info@universalintornatics.com
Perimeter of the Circle CASSIGNMENT
Area of the 37.680000
Circle 113.040001
inches =
square inches
15. Write aC
program to display multiple variables.
Sample
a*
Variables
C, X+C,dx +
x, (int) dx) +
ax, a+x, S+ b, ax +b,
Declaration: s+ C, ax+C, ax+ Ux
int a =
125, b =
12345,;
long ax 1234567890;=
short s= 4043;
float x 2.13459;
double dx =
1.1415927;
char c =
'WN';
unsigned long ux 2541567890; =
16. Write a C
program to convert specified days into years, weeks and days.
Note:
lgnore leap year.
Test Data
Number of days 1329
Expected Output:
Years:3
Weeks: 33
Days:3
UNIVERSAL INFORMATICS
www universalinformatics.comE-mail:info@universalinformatics.com
30. Write aC CASSIGNMENT
Write aC program
to
input month number and
31)
32. Write aC program to
count total number of print number of days In
that month.
program to notes in given
33.Write aC program to input angles a triangle and check amount.
of
triangle and checkwhether
34. Write
aC input all sides of a trlangle is valid or not.
35. Write program to check whether whether
aC the triangle Is valid or not.
36. Write program to find all roots of a triangle ls equilateral,
aC
program to calculate quadratic isosceles or scalene
37. Write
aC profit or loss. equatlon. triangle.
Caiculate program to input
marks of five
Percentagepercentage
> 90%:
and grade
according to
Grode A
subjects Physics, Chemistry,
Biology,
follaowing: Mathematics
Percentage >=
80% : Grade B
and
Computer.
Percentage >=
70% : GradeC
Percentage >=
60%:Grade D
tercentage >=
40% :
Grade E
fercentage <
40% :Grade F
J8. Write a C
progran to
tollowing
Basic Salary <=
input basic salary of an
employee and calculate its Gross
Basic Salary 10000 HRA salary according to
<=
20000 HRA
=
20%, DA =30%
Basic =
25%, DA
Salary> 20000: HRA
=
90%
=30%, DA 95% =
39. Write aC
program to
ondition: input electricity unit
For first 50
units ks.
charges and calculate total
For next
100 units Rs.0.50/unit electricity bill according to the
For next 100 0.75/unit given
units Rs.
For unit
above 250 Rs. 1.20/unit
An additional 1.50/unit
surcharge of 20% is added to the
0.)write aC program that bill
(Hoating points' values) accepts two item's weight
and
Test Data: calculate the average (floating points' values
Weight 1tem1: 15 value of the ) and number
items. of
purchase
No. of item1:5
Weight Item2: 25
No. of item2: 4
Expected Output
Average Value 19.444444
43.Write aC program that
received hour. Print theaccepts
employee'senployee's
per an
Test Data ID, total
ID and worked hours of
laput the salary (with two decimal places)month
a
and the
Input the Employees ID{Max. 10 chars): 0342 of a amount he
particular
working 15000
Salary amount/hr:hrs: 8 month.
Expected Output:
Einployees ID =u342
Salary US=
120000.00
42) Write aC
Test Data: program that accepts
three
hput the first integer: integers and find the
25 naximum of three.
UNIVERSAL INFORMAT!C
www.universalinformatics.com,E-mail:info@universatinfar1natics.co
CASSIGNMENT
nput the second integer: 35
nput the third integer: 15
xpected Output:
Maximum value of three integers: 35
Write a C program to calculate a blke's average consumption from the glven total distance (integer value)
raveled fin km) and spent fuel (n liters, float number-2 decimal polnt).
Test Data:
Input total distance in km: 350
Ioput total fuel spent in liters:5
Expected Outpiut:
Average consumption (kn/t) 70.000
4. Wnte a C program to read an amount (integer value) and break the amount into smallest possible number
of bank notes.
Test Data
Input the amount: 375
Expected Output:
here are:
3 Notels) of 100.00
1 Note(s) of 50.00
I Note(s) of 20.00
O Noteis) of 10.00
1 Note(s) of 5.00
O Note(s) of 2.00
O Notels) of
1.00
46. Write a Cprogram to convert a given inteyer(in seconds) to hours, minutes and seconds.
Test Data:
Input seconds: 25300
Expected Output:
There are:
H:M:5-7:1:40
A7.Write aCprogram to converta given integer (in days) to years, inonths and days, assumes that all months
have 30 days and all years have 365 ilays.
Test Data :
UNIVERSAL INFORMATIcS
www.universalinlormatics.comE-niall:info@universatin.formatics.rom
CASSIGNMENT
8)Wrnte a C
program that
gis 8reater thanr and s isaccepts
4
if integers p, 9,r, s from the user
"Correct values", otherwise greater than p and if the wherer ands are
sum ofr and s is positiveand p is even.
print "Wrong values. greater than the sum of p and
q print
Test Pthe m
Inpur' secondfltitan
integer: 35 to
input the third
integer: 15
Input the fourth
integer: 46
Expected Output:
Wrong values
9. Write a C
program to print the roots of
a
message if it is not Bhaskara's formula from the
possible to find the roots given three ffoating numbers.
Test Data: Display
Input the first
number(a): 25
Input the second number(b): 35
input the third number(c): 12
Erfcted Output:
HO Jtl= -0.60000
Root2 = -o.80000
50. Write a C
program that reads an integer and
message if the number is negative and check the specified
range where it belongs. Print an error
Test Data: greater
than 80.
Input an integer: 15
Expected Output:
Range (0, 20
loop
print all alphabets from a to z. using while loop
-
***
*****
****
*****
UNIVERSAL INFORMATICS
www.universalinformatics.comE-mail:info@universalyrmatics rr
CASSIGNMENT
..
Hollow Square Star PatternWeek 5
*****
****
****
*****
*****
****
*****
UNIVERSAL iNFORMATICS
www.universalinforniatics.com.E-mait:info@universalinforn
CASSIGNMENT
**
101. Write aC program that prints all even numbers between 1 and 50
est Data : (inclusive).
Even numbers between 1 to 50
(inclusive):
Expected Output:
2468 10 12 14 16 18 20 22 24 26 28 30 32 34
36 38 40 42 44 46 48 50
102. Write 3C program that read 5 nuirbers
and
Numbers. counts the number of positive numbers and negative
Test Data
Input the first number:5
lnput the second number: -4
Input the third number: 10
Input the fourth number: 15
nput the fifth number: 1
Expected Output:
Number of positive numbers: 3
umber of negative numbers: 2
UNIVERSAL INFORMATIcs
www.universalinformatics.com.E-mail:info@universalinforinatics.co
CASSIGNMENT
103. Write ac program that read 5 numbers and counts the number of
average of all positive values. positive numbers and print the
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
104. Write aC program that read S
numbers and sum of all odd values between
Test Data: them.
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
105. Write aC program to find and print the square of each one of
the even values from
Test Data: 1 to a
specified value.
List of square of each one of the even values from 1 to a 4:
Expected Output:
242- 4
42 16
106. Write a C
program to check a given integer is positive even, negative
Print even if the number is 0. even, positive odd or negative odd.
Test Data:
Input an integer: 13
Expected Output:
Positive Odd
107. Write aC
program to print all numbers between 1 to 100 which
remainder will be 3. divided by a specified number
and the
Test Data:
Input an integer: 25
EXpected Output:
28
53
78
108. Write C
a
progran that accepts some integers from the user and find the
position. highest value and the input
Test Data:
Input 5 integers:
UNIVERSAL INFORMATICS
www.universalinformatics.com.E-mail:info@universalinforn.atics.co
C ASSIGNMENT
15
23
a5
Expected Output:
Highest value: 45
Position: 5
109. Write aCprogram to print the numbers from the lowest to the highest (inclusive) and the sum of
consecutive integers from a given pair of numbers.
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
Sum=24
110. Write a C program to check if two numbers in a pair is 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!
UNIVERSAL INFCRMA:ICS
www.universalinfor1natics.com,E-maii:inf-@uiversa.clormJiics.201
CASSIGNMENT
a C program
131. Write find LCM of two numbers using recursion.
to
135. Write aprogrdm to find maximum and minimum element in an array. using recursion.-
a C program to find second
136. Write largest element in an array.
137. Write ac program to count total number of evert and odd elements in an array.
of a matrix.
1¬2. Write a C program to interchange diagonals
matrix.
C program to find upper triangular
163Write a
triangular matrix.
to find lower
164,Write a C program
165. Write a C program to find sum of upper trianguler matrix.
matrix.
166. Write a C program to find sum of lower triangular
find iranspose of a matrix.
167. Write a C program to
determinant of a matrix.,
168. Write a C program to find
matrix.
169. Write a C program to check ldentity
check Sparse matrix.
170. Write a C program to
C program to check
Sy1nmetric matrix
171. Write a
and use pointers.
tu create, initialize
172. Write aC program
to add two numbers using pointers.
Write aC program numbers using pointers.
a C progra1
tu "wap two
74. Write
to input and print array elements using pointer.
1%. wtite a Cprogram
another using pointers.
176. Write aCprogram to copy array to one
UNIVERSAL :iFORVANTICS
www.universalinformatics.com ë-mail:infuuniversali:ormatc.20*
CASSIGNMENT
a C program
Write to
multiply two matrix using pointers.
183, Write aC program to find
length of string using pointers.
184. Write a Cprogram to copy one string to another using pointers.
185. Write ac program to concatenate two strings using
C program
pointers.
126. Write a to
compare two strings using pointers.
C program
187. Write a to find reverse of a string using pointers.
188.Write ac program to sort array using pointers.
189. Write a C program to return multiple value from function using pointers.
190.Wrte aprgram to read a password until it is correct. 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
191. Write a Cprogram to read the coordinates(x, y) (in Cartesian system) and find the quadrant to which it
belongs (Quadrant -1, Quadrant -I1, Quadrant-l1, Quadrant -V).
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 (%,y)
coordinates are I(+,+), li (-+), lII (--), and IV (+-)
TestData:
Input the Coordinate(x,v):
X: 25
y:15
Expected Output:
Quadrant-l(++)|
192. Write a program that reads two numbers and divide the first number by second number. If the division
not possible print "Division not possible".
Test Dala:
Input two numbers:
X: 25
193. Write aC program to calculate the sum of all number iot divisible by 17 between two given integer
numbers.
TestData: 99
Input the first integer: 50 Input the second integer:
Expected Output:
Sum: 3521
Test Data:
nput the first integer: 25
liput the second integen: 45
Expected Output:
S0
UNIVERSAL INFORMATICS
www.universalinformatics.com.E-mail:into@universatinformstics.co
CASSIGNMENT
38
14
lines
line, starting from 1 and print lines. Accept number of
195. Write ac program to print 3
(n, integer) from the user.
numbers in a
n
Test Data
number of lines: 5
Input
Expected Output:
123
456
789
10 11 12
13 14 15
Test Data
number of lines: 5
Input
Expected Output:
111
2 48
3927
4 1664
5 25 125
p number of lines in a sequence of 1 to b in a
inputnumiber of lines:5
Number of characters in a line: 6
Expected Output:
123456
789i0 11 12
13 14 15 16 i7 18
19 20 21 22 23 24
25 26 27 28 29 30
Test Data 10
Input Mathematics marks (0 to terminate):
20
Eypected Output:
Mathematics: 17.50
HVerage marks in
199. Write a C program to calculate the value of S where S = 1 + 1/2+ i/3 .. 1/50.
txpected Output
UNIVERSAL INFORMATIeS
www.universalinformatics.ccn,E-:nail:infouniversen 'ormatics.ru
CASSIGNMENT
S: 4.50
Value of
series: 4.62
Value of
201. Write ac program that reads an integer and find all its divisor.
Test Data:
integer: 45
Input an
Expected Output:
202. Write a C program to read and print the elements of an array of length 7, before print replace every
negative number, zero with 100.
Test Data:
Input the 5 members of the array:
Expected Output:
Array vaiues are:
n0= 25
n[1)= 45
n2] 35
n[3 0
n[4] 15
203. Write a C program to reaú and print the elements of an array of length 7, before print, put the triple of
the previous position starting from the second position of the array.
For example, if the first number is 2, the array numbers must be 2, 6, 18, 54 and 162
Test Data:
204. Write a C program to read an array f length 5 and print the position and value of the array elements of
value less than 5.
Test Data:
UNIVERSAL INFORMATICS
www.universalinformatics.ccm,E-mail:info@univer: informe ics. u
C ASSIGNMENT
Input the
5 members of the
array (15
15
25
4
35
40
Expected Output:
A[2]=4.0
to read an array of length 6, change the first element by
the last, the second element
205. Write acprogram
of the modified array.
and the third element by the fourth. Print the elements
by the fifth
Test Data:
5 members of the array:
Input the
15
20
25
30
35
Expected Output:
array_n[0] -35
arrayn[1= 30
array_n[2]= 25
=
20
array n[3]
array n[4)= 15
string to lowercase.
convert uppercase
211. Writea C program to
ofeach character of string-
a
2. Write aC program to
occurrence oí a character from string.
227. Mrite a C program to r e m o v e iast
occurrences ofa character
from string.
.8. Write a C program to remave all
UNIVERSAL INFORMATICS
www.universalinformatics.com,E-mail:infro@urive saliniornatS.co
CASSIGNMENT
229. Write at program to remove all repeated characters from a given string
230. Write a program to replace first occurrence of a character with another ina string.
231. Write aprogrdm to replace last occurrence of a character with another in a string
232. Write aprogram to replace all occurrences of a character with another in a string.
233. Write aC program to find first occurrence of a word in a given string
234. Write acprogram to
find last occurrence of a word in a given
Write a program to search all occurrences of a word in given
string
235. string
236. Write ac
program to count occurrences of a word in a
given string
237. Write aCprogram to remove
first occurrence of a word from string
238. Write a to remove last occurrence of a word in
Cprogram given
239. Write ac program to remove all occurrence of a word in given string.
string
240. Write a C program to trim leading white space characters from given string
.241. Write a c program to trim trailing white space characters from given string.
242. Write acprogram to trim both leading and trailing white space characters from given string
243. Write a C program to remove all extra blank spaces from given string.
244. 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
interest.
245. Write a C program that accepts principle, rate of interest, time and compute the simple
Test Data:
p= 10000,r= 10%, t =
12 year
input Data:
Expected Output:
simple interest:
Input principle, Rate of interest & time to find
Simpleinterest 12000
lest Data:
Input Data: 500cms
in cm:
Input the distance
Distance of 500.00 cms is = 196.85 inches
input value:2
Read the integer from keyboard-
Integer value = 2
UNIVERSAL INFORMATICS
www.universalinformatics.comE-inailinf.@universalinfor.n.ics.con
CASSIGNMENT
234
number =
The original
The reverse of the said number =432
numbers from the keyboard and print out the difference of the
250. Write a C
program that accepts 4 real
mininmum values of these four numbers.
maximum and
four numbers: 1.54 1.236 1.3625 1.002
Input
Difference is 0.5380
a C program to create enumerated data type for 7 days and display their values in integer
252. Write
constants.
Sun = 0
Mon = 1
Tue2
Wed =3
Thu 4
Fri - 5
Sat = 6
real number and prints out the corresponding value of sin(1/x) using
253. Writea Cprogram that accepts a x
4-decimal places.
Input value of x: .6235
Value of sin(1/x) is 0.9995
number.
Input a positive number less than 500:
Sum of the digits of 347 is 14
less than 100 from the user and prints out the sum 14
255. Writea C program that accepts a positive integer n
+24+44+ 74+ 114+**m4, where m is less than or equal ton. Print appropriate message.
UNIVERSAL INFORMATICS
www.universalinformatics.comE-mail:info@universaliaformatics.com
257. Write aprogram that prints out the
CASSIGNMENT
prime numbers between
(1
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:
235711 13 17 19 23 29
31 37 4143 4753 59 61 67 71
73 79 83 8997 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197
258. Write ac program that generates 50 random numbers between -0.5 and 0.5 and writes them in a file
rand.dat. 1he tirst ine of ran.dat contains the number of data and the next 50 lines contains the 50 random
numbers.
50
-0.4215
0.2620
0.3065
-0.0485
.0.3980
0.1750
0.478
-0.2915
0.0715
0.3565
259. Write aC 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
260. Write aC program to print the powers of 2 table for the power 0 to 10, both positive and negative.
====***======**--==========
n2 to power n 2 to power -n
========-== **
01 1.000000000000
120.500000000000
240.250000000000
380.125000000000
4 16 0.062500000000
S 32 0.031250000000
6 64 0.015625000000D
7 128 0.C07812500000
3 256 0.003906250000
9512 0.001953125000
10 1024 0.000976562500
=zz======
UNIVERSAL INFORMAT'CS
www.universalinformatics.com.E-mail:info@unive:valiniormatics.com
CASSIGNMENT
263. StoreIntormation(name, Id and salary) of a Employee Using Structure
264. C Program to store Information Using Structures with Dynamically Memory Allocation
****
01
11
2121
31331
414641
515 10 105 1
616 15 20 15 61
71721 35 35 21 71
81828 56 70 56 28 8 1
91936 84 126 126 84 3691
10 1 1045 120 2:0 252 210 120 45 101
289. Write a C program to print the alphabet set in decimal and character form.
[65-A 66-8] [67-C} 168-D] [69-E] [70-F] {71-G] [72-H] [73-1] [74-J] [75-K] {76-L] {77-M] [78-N] [79-0] [80-P] [81-Q
82-R} {33-S] (84-T] 185-U] [86-V] [87-W] [88-xj 189-V
[90-2] {97-a] [98-b] [99-c] [100-d] [101-e] [102-1] |103-g) {204-h} [105-i] |106;} [107-k] [108-1) {109-m] [110-n]
111-cl[112-p] [113-q] [114-r] [115-s] [116-t] [117-u] {118-v]
[119-1120-x] |121-vl [122-z]
0 . Write a C program to copy a given string into another and count the niumber of characters copied.
Inpst a string
Origitai tring: w3resource
Number of cnaracters = 10
UNIVERSAL INFORMATICS
www.universalinformatics.comE-mail:info@univessalin.ormatics.com
CASSIGNMENT
291. Write aCprogram to
remove any
2
Input a value (negative): negative sign in front of a number.
Original value = -253
292. Write a c
programming that reads in two
second integer. integers and check whether the first
integer is
Sample Input: 9 3
a
multiple of the
Sample Output:
Input the first integer Input the second
9 is a multiple of 3. integer:
293. Write aC
programming to display the integer
Sample Output: equivalents of letters (a-z, A-2).
List of integer equivalents of letters (a-z, A-Z).
*****
294. Write C
a
programming that accepts one seven-digit number
digits, and prints the digits separated from and separates the number into its individual
Sampie input: 2345678 one another by two spaces each.
Input a
seven digit
Output:2 3 4 5678number
295. Write aC
programming to calculate and
display them in a table of values. prints
uses tabs to the squares and
cubes of the numbers from 0 to 20
Sample Output: and
Number Square Cube
000 **
111
48
3927
18 2245832
19 361 6s59
20 400 8000
L9t.
Write aC
ne
simple interest for orogramming that accepts principal amouni, rate of
intëres= principal
the loan, using the interest and days 'or
"
UNIVERSAL INFORMATICS
www.universalinformatics.com,E-mail:info@universanforma'ics.com
CASSIGNMENT
10000
1
365
Sample Output:
Input loan amount (0 to quit): Input interest rate: Input term of the loan in days: The interest amount is
S1000.00
Input loan principaamt (0 to quit):
297. Write a Cprogramming to demonstrates the difference between predecrementing and postdecrementing
using the decrement operator -
Sample Output:
Predecrementing
x = 10
= 10
x = 9
Sample Output:
x+2 x+4 xt6
x
* *
6 8 10
7 9 11 13
10 12 14 16
13 15 17 19
# ##### # ###
###### # ## #
##########
# ####### ##
###### # # ##
##########
###t#### *#
######## ##
##########
#####H ####
between 1 and 10 ) of a square and prints a hollow
300. Write aC programming that reads the side (side sizes
square using hash (#) character.
Sample Input: 10
Sample Output:
Input the size of the square:
####*###*
UNIVERSAL INFORMATICS
www.universalinformatics.comE-mail:info@universaBiformatics.con
CASSIGNMENT
###R##*#*#
301. Write aC programming Write a program that reads in a five-digit integer and determines whether or not
it's a palindrome.
Sample Input: 33333
Sample Output:
Input a five-digit number: 33333 is a palindrome.
302. Write a C programming which reads an integer (7 digits or fewer) and count number of 3s in the given
number.
Sample Input: 538453
Sample Output:
Input a number: The number of threes in the said number is 2
303, Write aC programming to calculate and print the average of some integers. Accept all the values
preceding 888.
Sample Input:12
15
24
888
Sample Output:
Input each number on a separate line (888 to exit):
The averege value of the said numbers is 17.000000
304. Write a C programming to print a table of all the Roman numeral equivalents of the decimal numbers in
the range 1 to 50.
Sample Output:
Decimal Roman
number numeral
--******-***
lli
V
****
LXXXXVilI
39 LXXXXIX
10C C
UNIVERSAL INFORMATICS
www.universalinformatics.comE mail:info@univ. somatics.com