Elab

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

eLab1.

o
C Programming Sessions
1. Input and Output
2. Data types
3. Operators
4. Control and Looping Statements
5. Arrays
6. Strings
7. Functions
8. Structures and Unions
9. Pointers
10.Practice Session
SRIVI University Learning Centre
eLab - 1.0 PDD JAN 2017 1st Edition

Course: C 11
Subject Code:
Q. IO 10
Sneha got a sin
solve with the to
operation(c+=3
operation lnput
decimal places.
Source Code
#lnclude <stdio.h>
int main()
i
lnt a, c;
scanf("%d".&a):
c = a;
printf("\nc=%d". c);
c+=a://c=c+a
D
printf("\nc+= /od", c)
c-=a;/rc=c-a
prlntf("\nc-=/od". c)
C'=a;//C=C~a
printf("\nc*=%d", c)
c/=a://c=c/a
printf("\nc./=%d", c)
c %= at // c = c%a
printf("\nc/o%=%d"
retum 0;
l
Sample Input
3
Sample Outpu
c=3
mud,
2Q$
(J
O
Result
Thus, Program
!
v
t
gle integer as an input , and her task to perfonn all assignment operations in with
the given input . Let us help her to
llowing conditions met, To Perform , Assign an input the new the variable and
display Using addition assignment
c=c+3) Using Subtraction assignment operation Using division assignment operation
Using modulus assignment
and Output Format: Refer sample input and output for formatting specification. All
float values are displayed correct to 2
All text in bold corresponds to input and the rest corresponds to output.
2
C);
" IO 10 " has been successfully executed

course: C Spbject Code:


Q. IO11
Write a program to calculate area of a circle lnput and Output Format: Refer sample
input and output for formatting specification. All float
values are displayed correct to 2 decimal places. All text in bold corresponds to
input and the rest corresponds to output
Source Code
#include<stdlo.h>
lnt maln() {
oat radius, area;
$C8l'lf("/of", &radius);
area = 3.14 ' radius radius;
printf("\nArea of C|t'C|9Z/of", area);
printf("\nArea of Circle:%.2f"_ area);
retum 0;
)
Sample Input
2
Sample Output
Area of Circle:12.560000
Area of Circle: 1 2.56
Result
Thus, Program " IO 11 " has been successfully executed

course: C Spbject Code:


Q.lO 12
Write a program to print the ASCII value of a character Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude <stdio.h>
int main()
l
char c;
scanf("%c", &c);
printf("ASC|l value of %c=%d", <:. c);
return 0:
l
Sample Input
c
Sample Output
ASCII value of c=99
Result
Thus, Program " IO 12 " has been successfully executed

course: C Srbject Code:


Q.lO 14
Ram was a popular maths teacher, he gave a 4 digit number to his students as a
assignment .He has to identify ones portion of given
number. Please help his students to identify and display the output: Input and
Output Format: Input can be an integer Explanation : Let
us say ram given number is 1234 and his student need to identify ones portion is 4
Source Code
#|nciude <stdio.h>
int main() {
int num.digit_At_ones_p|acce;
scant("/ed". &num);
dlg|t_At_ones_placce=num%10;
printf("\nThe Digit at ones place of %d is:%d", num,digit_At_ones_p|acce):
retum 0:
l
Sample Input
72
Sample Output
The Digit at ones place of 72 is:2
Result
Thus, Program " IO 14 " has been successfully executed

course: C Subject Code:


Q. I015
write a program to swap two numbers using a temporary variable Input and Output
Format: Refer sample input and output for formatting
specification. All oat values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude <stdio.h>
lnt maln()
l
lnt x, y, temp;
scanf("%d/>d". &x, &y)l
printf("Before swapping:%d %d",x,y);
temp = x:
x = y:
y = temp:
printf("\nAfter swapping:%d %d",x,y);
retum 0;
l
Sample Input
5 4
Sample Output
Before swapplng:5 4
After swapping:4 5
Result
Thus, Program " IO 15 " has been successfully executed
course: C Spbject Code:
Q. IO 16
Write a program to swap two numbers without using a temporary variable Input and
Output Format: Refer sample input and output for
formatting specification. All float values are displayed correct to 2 decimal
places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#lnclude<stdlo.h>
int maln()
l
int a,b;
scanf("%d/>d",&a,&b);
printf("Before swapping:%d %d",a,b);
8 = a+b;
b = H D:
a = a - bi
printf("\nAfter swapping:%d %d",a,b);
retum 0;
)
Sample Input
5 4
Sample Output
Before swapplng:5 4
After swapping:4 5
Result
Thus, Program " IO 16 " has been successfully executed

course: C Stibject Code:


Q. IO 18
Write a program to convert Fahrenheit into celsius Input and Output Format: Refer
sample input and output for formatting specication
All oat values are displayed correct to 2 decimal places. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#include<stdIo.h>
lnt maln()
l
oat th,cl:
scanf("%t"',&th)1
cl =(th - 32)/ 1.8;
printf("/<>O.2tC",cl);
retum 0:
l
Sample Input
0
Sample Output
-17.780
Result
Thus, Program " IO 18 " has been successfully executed

course: C Srbject Code:


Q. IO 19
Heera is a cute little gal of age 5 years old, she had one piggybank to save money
(coins). Her piggy bank got full and she was excited
to her savings money. So, she classified the coins of its followings types , Rs.1O
coins, Rs. 5 Coins , Rs .2 Coins, Rs. 1 Coins. Now
Please help her to calculate the total amount she saved? Input : total number of
coins collected on every classified type respectively(
Rs..10 Coins, Rs. 5 Coins, Rs. 2 coins, Rs.1 Coins)
Source Code
#|nclude<stdlo.h>
lnt maln()
l
lnt num_1O,num_5,num_2,num_11
float total;
scanf("%d",&num_10):
scanf("/<>d.&num_5);
scanf("%d".&num_2);
scanf("%d".&num_1);
total=num_10'10+num_5'5+num_2'2+num_1'1;
printf("\nTota| amount In the piggybank=%0.2f,total);
retum 0:
l
Sample Input
10 23 43 6
Sample Output
Total amount In the piggybank=307.00
Result
Thus, Program " IO 19 " has been successfully executed

course: C Srbject Code:


Q. IO 20
Carmel is an shopkeeper help him to generate the bill amount of an item given its
quantity sold ,value ,discount (In %) and tax(ln %)
Input and Output Format: Refer sample input and output for formatting
specification. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#lnclude <stdio.h>
Int main()
i
oat total_amount, amount, sub_total, discount_amount, tax_amount, quantity, value,
discount. tax;
scanf ('%f". &quantity) ;
$C&l'lf("/of", &value);
scanf("%f", &discount);
scanf ('/of. &tax) ;
amount = quantity " value:
discount_amount = (amount' discount)/100.0;
sub_total =amount - discount_amount;
tax_amount= (sub_totaltax) /100.0;
total_amount =sub_total+ tax_amount:
printf ("\nBill") ;
printf("\nQuantltySold:%f", quantity);
printf("\nPrice per item:%f", value);
printf ("\nAmount:%f. amount):
printf ("\nDiscount:-%f_ discount_amoun'l) ;
printf ("\nDlscounted Tota|:%l", sub_tota|) ;
printf ("\nTax:+%f", tax_amount);
printf ("\nTotal Amount:/>f", total_amount);
retum O;
l
Sample Input
20 300 10 12
Sample Output
Bill
QuantitySold:20.000000
Price per item:300.000000
Amount:6000.000000
Discount:-600.000000
Discounted Total:5400.000000
Tax:+648.000000
Total Amount:6048.000000
Result
Thus, Program " IO 20 " has been successfully executed

course: C Spbject Code:


Q. IO 21
Write a program to convert a floating point number into corresponding integer Input
and Output Format: Refer sample input and output
for formatting specification. All float values are displayed correct to 2 decimal
places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#include<stdlo.h>
Int main()(
float f_num;
lnt l_num;
scanf("%f",&f_num);
l_num = (lnt)f_num;
printf("\nThe integer variant of %0.2f is=%d",f_num,i_num):
retum 0:
l
Sample Input
12.01
Sample Output
The integer variant of 12.01 ls=12
Result
Thus, Program " IO 21 " has been successfully executed

Course: C H
Q. IO 22
Subject Code
Given an input as integer to the machme he need to get the output of correspondmg
oatmg pomt number wlth five dlgrt after decumal
points. Please help h|m to wr|te the program that satlsfy the output Input and
Output Format Refer sample lnput and output for
formatting specicatron All text |n bold corresponds to mput and the rest
corresponds to output
Source Code
#include<stdio.h>
Int main()(
float F_num;
int |_num;
scanf("%d".&i_num);
F_num = (f|oat)i_num;
printf("\n%0.5f'.F_num)
printf("\n%d".i_num);
retum 0:
l
Sample Input
12
Sample Output
12.00000
12
Result
Thus, Program IO 22 " has been successfully executed

Course: C Srbject Code:


Q. IO 23
Mr.Ftight is an english teacher , he got task to to calculate a students result
based on input of two examinations ,one sport event , and
three activities conducted . Please help him to find the result of every individual
section according to weightage(Glven below) provided
by principal that results to exam _percent, sports percent,activities percent and
finally total percent that sums all individual result with
following conditions met Weightage : ACTlV|TlES_WElGHTAGE- 30 SPORTS_WElGHTAGE- 20
EXAMS_WElGHTAGE -50 Total :
EXAMS_TOTAL out of 200 ACTlVlTlES_TOTALout of 60 SPORTS_TOTAL out of 50 lnput: Two
scores obtained in two examination
(out of 100) The score obtained in sports events (out of 50) The score obtained in
three activities (out of 20) Explanation :To calculate
exam percent=(Addion of two exam marks) * (Weightage of Exam) / (Total_score based
on no of exam inputs)
Source Code
#lnclude<stdlo.h>
#dene ACTlVlTlES_WElGHTAGE 30
#define SPOFtTS_WElGHTAGE 20
#define EXAMS_WElGHTAGE 50
#dene EXAMS_TOTAL 200
#dene ACTlVlTlES_TOTAL 60
#define SPOFtTS_TOTAL 50
lnt main()
l
lnt exam_scorel. activities_scorel,sports_score;
lnt exam_score2. activlties_score2.actlvitles_score3I
oat exam_total. actlvitles_total;
float total _percent. exam_percent,sports_percent. activities_percent:
scanf("%d %d", &exam__scorel, &exam__score2);
scant("%d",8.sports_score);
scanf("/ed %d %d",&activities_scorel,&activities_score2,&actIvitles_score3)1
exam_total = exam_scorel + exam_score2:
activitles_total = (actlvlties_scorel + activlties_score2 + activities_sc0re3);
exam _percent = (tloat)exam_total EXAMS_WElGHTAGE I EXAMS_TOTAL;
sports _percent = (oat)sports_score ' SPORTS_WElGHTAGE / SPORTS_TOTAL;
actlvitles_percent = (tloat)activltles_totaI
ACTIVITIES_WElGHTAGE/ACTIVITIES_TOTAL:
total _percent = exam _percent + sports _percent + actlvlties_percent;
printf("\nResult") ;
printf("\nTotal Percent in examination:%0.2f', exam _percent);
printf("\nTotal Percent In activitles:%0.2f. activlties_percent)2
printf(\nTotal Percent In sports:%O.2t", sports _percent);
printf("\nTotal Percentage:%0.2t", total _percent);
retum 0:
l
Sample Input
7889
34
191817
Sample Output
Result
Total Percent in examlnatlon:41.75
Total Percent in activlties:27.00
Total Percent in sports:13.6O
Total Percenlage:82.35
Result
Thus, Program " IO 23 " has been successfully executed

course: C frbject Code:


Q. IO 24
Selva Mary from SRM Public school is studying 3r grade in school, her maths mam
gave her a problem to convert the decimal number
in octal and hexadecimal . Since her mam gave so much problems to solves.She went
to his brother who is computer programmer and
requested to create a program that converts automatically given integer to decimal,
octal and hexadecimal equivalent. Let us help an
programmer to do program? Refer sample input and output for formatting
specication. All oat values are displayed correct to 2
decimal places. All text in bold corresponds to input and the rest corresponds to
output.
Source Code
#include<stdlo.h>
int main()(
lnt decimal:
scanf("%d".&decimal);
printf("\nDecimal value:%d\nOctal value:/<>o\nHexadecimal va|ue:/>x". decimal.
decimal. decimal);
retum 0:
l
Sample Input
25
Sample Output
Decimal V8|U9I25
Octal value:31
Hexadecimal value:19
Result
Thus, Program " IO 24 " has been successfully executed

course: C Spbject Code:


Q. IO 25
Write a program that prints a floating point value in ex
within 6 columns Tries to print number right justified to
Rounds to 0 digit places Prints the number in expone
output for formatting specification. All float values are
rest corresponds to output.
Source Code
#lnclude <stdio.h>
int main()
l
int a=l .integer;
oat decimal:
scanf("/<>d",&integer);
scanf("/<>f".&decimal);
printf("\n4 digit integer right justied to 6 column:%4d", integer);
printf("\n4 digit integer right justied to 3 column:%3d", integer):
// Rounds to two digit places
ponentiai format with the following specifications Prints the number right
justified
3 digits but the number is not right adjusted because there are only 4 numbers
ntial notati0n(scientific notation) input and Output Format: Refer sample input and
displayed correct to 2 decimal places. Ali text in bold corresponds to input and
the
printf("\nFl0ating point number rounded to 0 digits:%.f".987.6543);
printf("\nFloating point number rounded to 2 digits:%.2t",decimal);
printf("\nFIoating point number rounded to 4 digits:%.4f",decimal);
// Rounds to 0 digit places
printt("\nFioating point number rounded to 8 digits:%.8f",decimal);
// Prints the number in exponential notation(scientific notation)
printf("\nFloating point number in exponential form:/oe".987.6543)
retum 0:
) .
Sample Input
9876
987. 6543
Sample Output
4 digit integer right justified to 6 coiumn:9876
4 digit Integer right justified to 3 coiumn:9876
Floating point number rounded to 0 digits:988
Floating point number rounded to 2 diglts:987.65
Floating point number rounded to 4 digits:987.6543
Floating point number rounded to 8 digits:98'/165429688
Floating point number In exponential form:9.876543e+02
Result
Thus, Program " IO 25 " has been successfully execu
ted

course: C Srbject Code:


Q. IO 26
Write a program to read 10 integers. Display these numbers by printing three
numbers in a line separated by commas Input and Output
Format: Refer sample input and output for formatting specification. All float
values are displayed correct to 2 decimal places. All text in
bold corresponds to input and the rest corresponds to output.
Source Code
#include<stdlo.h>
int maln()(
rm a,b_c,d,e,t.g,h,i.];
scanf("%d %d %d %d /od %d %d %d %d />d", &a,&b,&c,&d,&e.&f,&g.&h,&l,&i);
printf("\n%d.%d,%d\n%d.%d./<>d\n%d,/<>d.%d\n%d", a,b.c.d,e,f.g.h,i.j):
retum O:
l
Sample Input
1 2 3 4 s s 7 a 9 10
Sample Output
1,2,3
4,5,6
7.a,s
10
Result
Thus, Program " IO 26 " has been successfully executed

Course: C 11
Q. IO 28
Subject Code
Write a program to pr|nt the count of even numbers between 1 and 200 and pnnt their
sum Input and Output Format Refer sample |nput
and output for formatting specrfrcatron All float values are displayed correct to 2
decrmal places All text In bold corresponds to mput and
the rest corresponds to output
Source Code
#include<stdlo.h>
rm maln()
l
lnt a=0.i;
for(i=0;i<=200;i=i+2)
at-=|;
printf("%d",a);
retum O:
l
Sample Input
0
Sample Output
0
Result
Thus, Program " IO 28 " has been successfully executed

Course: C 11
Subject Code:
Q. IO 29
Write a program
specication. All
output.
Source Code
#lnclude<stdlo.h>
int maln()
l
char ch[10];
int l,count=0;
scanl("%s",ch);
for(i=O;ch[i]l='\0;i++)
l
lf(ch[|]=='a || n[|]=='
ll hlil=='u')
(
count++:
l
l
printf("\nVowe|s=/
od
retum 0:
l
Sample Input
srmunlversity
Sample Output
Vowels=4
Result
Thus, Program "
to count numbers of vowels in a text Input and Output Format: Refer sample input
and output for formatting
float values are displayed correct to 2 decimal places. All text in bold
corresponds to input and the rest corresponds to
e || ch[l]=='l' ;| ch[l]=='o'
",COl.lt]
IO 29 " has been successfully executed

course: C ibject Code:


Q. I03
Write a program to calculate the perimeter of a tnangle using Heros formula Input
and Output Format: Refer sample input and output for
formatting specification. All float values are displayed correct to 2 decimal
places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#lnclude<stdlo.h>
#lnclude<math.h>
Int main()(
float a,b,c;
float s,area;
scanf('%f%f%f" .&a. &b_&c);
s = (a+b+c)/2;
area = sqrt(s'[s-a)"(s-b)(s-c));
printf("perlmeter of triangle ls:%f"_.area);
return 0:
l
Sample Input
2 3 4
Sample Output
perimeter of triangle is:2.904737
Result
Thus, Program " IO 3 " has been successfully executed

course: C Srbject Code:


Q. IO 30
Write a program to read the address of a user .Display the result by breaking it
into multiple lines Input and Output Format: Refer sample
input and output for formatting specification. All float values are displayed
correct to 2 decimal places. All text in bold corresponds to
input and the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
//#lnc|ude<conio.h>
Int maln()
l
lnt hno;
long Int pin:
char area[20];
SC8f("/oC|'. &hn0)2
scanf("%s", area);
scanf("/old", &pln):
printf("Address");
printf("\nHouse Number:%d", hn0)I
printf("\nArea:%s". area):
printf("\nPln Code:%|d", pin);
retum 0;
l
Sample Input
3489
SRMChennai
603203
Sample Output
Addl'9SS
House Number:3489
Area:SRMChennal
Pin Code:603203
Result
Thus, Program " IO 30 " has been successfully executed

course: C Srbject Code:


Q. IO 31
Pranav intelligent in playing riddle with numbers so, he gave his sister a puzzle
to solve in which she need to solve by adding the left
side integral part of two decimal numbers. Explanation: Raju gave his sister two
decimal numbers : 23.44 and 33.22 , His sister need to
identify the left side integral part of given numbers are 23 and 33 . Finally the
added output value is 56. Input and Output Format: Refer
sample input and output for formatting specification. All float values are
displayed correct to 2 decimal places. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#|nclude<stdlo.h>
lnt main()
l
float a_b;
lnt sum:
scanf("%f", &a);
scanf("%f", &b):
sum = (int) a+b;
printf("\nsum:%d".sum);
retum 0;
l
Sample Input
12.22
11.22
Sample Output
sum:23
Result
Thus, Program " IO 31 " has been successfully executed
course: C Srbject Code:
Q. I0 32
Manav had a play with his friend gourav, he gave a number that to read a floating
point number and asked him to display the right most
digit integral part of the number. Please help gourav to display the right most
integral part of the number. Explanation : If the input is
given 124.34, then the output to be displayed is 4 (i.e) Before decimal the
integral part is 124 , in that last digit is 4. Input and Output
Format: Refer sample input and output for formatting specification. All float
values are displayed correct to 2 decimal places. All text in
bold corresponds to input and the rest corresponds to output.
Source Code
#Include<stdlo.h>
lnt main()
l
float a;
lnt num, digit;
scanf("%t", Sta);
num = (lnt)a;
digit = num%10;
printf("Rightmost integer digit of %t=%d,a,digit);
retum 0;
l
Sample Input
233.444
Sample Output
Ftightmost lnteger digit of 233.444000=3
Result
Thus, Program " IO 32 " has been successfully executed

course: C Srbject Code:


Q. IO 33
Raj deposit $10000 into a bank account paying 7% simple interest per year. He left
the money in for 5 years. Find the interest earned
and the amount at the end of those 5 years by Raj? Help him to find the interest
and amount resided in bank after 5 years? STEP 1:
Find an interest by using the formula l=P<=i<=t, where I is interest, P is total
principal, i is rate of interest per year, and t is total time in
years. STEP 2: Find an amount by using the formula A=P+l. Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude<stdlo.h>
#lnclude<math.h>
int maln()
l
oat p. r, t. interestamount;
scanf("%f%f%f",&p,&r.&t);
lnterest=(p'r*t)/100;
amount=lnterest+p;
printf("\nlnterest=%0.2f"_interest)2
printf("\nAmount=%0.2f",amount);
retum 0;
l
Sample Input
10000
7
5
Sample Output
|nterest=3500.00
Amount=13500.00
Result
Thus, Program " IO 33 " has been successfully executed

course: C Srbject Code:


Q. IO 34
Help Raja to calculate a first salary that he got from the organization , he was
confused with an salary credited in hs account . He asked
his friend ritu to identify how salary pay got calculated by giving the format of
salary . His basic pay (to be entered by user) and Ritu
developed a software to calculate the salary pay,with format given as below
HFlA=80% of the basic pay, dA=40% of basic pay . bonus =
25 % of hra input and Output Format: Refer sample input and output for formatting
specification. All float values are displayed correct to
2 decimal places. All text in bold corresponds to input and the rest corresponds to
output
Source Code
#inciude<stdio.h>
#detine HRA 0.80
#define TA 0.40
int maln()
i
oat basic. sal;
scanf("/<>f".&basic);
sai = basic + (HRA ' basic) + (TA basic);
printf("Totai Saiary=%f,sai):
retum O:
l
Sample Input
50000
Sample Output
Total Salary=1 1oooo.oooooo
Result
Thus, Program " IO 34" has been successfully executed

course: C Spbject Code:


Q. IO 35
Write a program to display a grocery bill of the product purchased in the small
market by John by getting following input from the user
Get the product name Get the price of the pr0duct(Price per Unit) Get the quantity
of the product purchased lnput and Output Format:
Refer sample input and output for formatting specification. All float values are
displayed correct to 2 decimal places. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#|nclude<stdlo.h>
int ma|n()(
char prod_name[10]:
Int qty;
float prod _price,tot _prlce:
scanf("%s",prod_name);
scanf("/t>f",&prod_price);
scanf("%d".&qty);
tot _prIce=qty'prod _pricel
printf("\nProduct Details");
printf("\n%s",prod_name)I
printf("\n%f,prod_price);
printf("\n/<>d".qty);
printf("\nB||l:%0.2f",tot_prlce);
retum 0;
l
Sample Input
soap
33.00
2
Sample Output
Product Details
soap
33.000000
2
Bill 266.00
Result
Thus, Program " IO 35 " has been successfully executed

course: C Spbject Code:


Q.lO4
Given two cities at geographic coordinates (xA,yA) and (xB,yB), and calculate the
distance between from city A to city B? Note: Use the
distance between points formula Input and Output Format: Refer sample input and
output for formatting specification. All float values are
displayed correct to 2 decimal places. All text in bold corresponds to input and
the rest corresponds to output.
Source Code
#lnclude<stdio.h>
#lnclude<math.h>
lnt maln()
t
lnt x1. y1, x2, y2:
oat dist;
scanf("%d%d".&x1 .&y1 );
scanf("%d%d",&x2,&y2);
dist=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
printf("\nThe distance between two points ls:%0.2f units",dist);
retum O;
l
Sample Input
1233
134
Sample Output
The distance between two points is:29.02 unlts
Result
Thus, Program " IO 4 " has been successfully executed

course: C Srbject Code:


Q. I05
Write a program to scan the given input and perform unary prefix increment and
decrement operators. Condition : Variable name to be
used: Preadd, Presub, Posadd, Possub
Source Code
#include<stdlo.h>
int ma|n()
l
int num,posadd,possub,preadd,presub;
scanf("/od'.&num)l
posadd=num++;
possub=num--;
preadd=++num;
presub=--num;
printf("\nThe Value of num=%d".num);
printf("\nThe Value of num++=/>d", posadd);
printf("\nThe new Value of num=%d"_preadd):
printf("\nThe Value of num=%d",preadd);
printf("\nThe Value of num~-=/>d".possub);
printf("\nThe new Value of num=/odipresub);
retum O:
l
Sample Input
2
Sample Output
The Value of num=2
The Value of num++=2
The new Value of num=3
The Value of num=3
The Value of num--=3
The new Value of num=2
Result
Thus, Program " IO 5 " has been successfully executed

course: C Spbject Code:


Q. I08
Write a program to find the largest of three numbers using ternary operator Input
and Output Format: Refer sample input and output for
formatting specication. All oat values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest
corresponds to output.
Source Code
# include <stdio.h>
rm main()
i
int a, b, c. big;
scanf("/<>d %d %d", &a, &b, &c) 1
big=(a>b)?((a>c)?a:c):((b>c) ?b:c):
printf('\nThe biggest number ls:%d, big) ;
return 0;
l
Sample Input
4 5 6
Sample Output
The biggest number ls:6
Result
Thus, Program " IO 8 " has been successfully executed
Course: C Spbject Code:
Q. I09
Let us help Raje to perform basic bitwise operation by providing three inputs given
to the program with the following conditions are met,
Bitwise And Bitwise OR Bit Wise Not complement of Positive number complement of
negative number Right shift by 0 of given number
Right shift by 1 of given number Left shift by 0 of given number Left shift by 1 of
given number Input and Output Format: Refer sample
input and output for formatting specification. All float values are displayed
correct to 2 decimal places. All text in bold corresponds to
input and the rest corresponds to output.
Source Code
#IncIude <stdio.h>
int main()
(
int a, b,c;
scanf("%d/<>d%d",&a.&b,&c):
printf("Bitwise And of /<>d and %d=%d\n", a.b.a&b):
printf("Bitwlse OR of %d and %d=%d\n.a.b, alb);
printf("Bit Wise Not of %d and %d=%d\n", a,b,a'\b);
printf("complement of /od=/od\l\",8,'-3)}
printf("compIement of -%d=%d\n'.b.~-b);
printf("Rlght shift by 0 of %d=%d\n".c,c>>0);
printf("R|ght shift by 1 of /<>d=%d\n".c.c>>1);
printf("Left shift by 0 of %d=%d\n",c,c<<0);
printf("Left shift by 1 if %d=/od\n".c,c<<1);
retum 0:
l
Sample Input
23 4 4
Sample Output
Bitwise And of 23 and 4=4
Bitwise OR of 23 and 4=23
Bit Wise Not of 23 and 4=19
complement of 23=-24
complement of -4=3
Right shift by 0 of 4=4
Right shift by 1 of 4=2
Left shift by 0 of 4=4
Left shift by 1 if 4=8
Result
Thus, Program " IO 9 " has been successfully executed

course: C Subject Code:


Q. Hello Welcome to SRM University
On Syams First class of Type-writing the teacher told him to write the word Hello
Welcome to SRM University! Please help him to print
hello world the give text
Source Code
#include <stdio.h>
lnt maln()
l
printf("He||o Welcome to SRM University");
return 0;
l
Sample Input
0
Sample Output
Hello Welcome to SRM University
Result
Thus, Program " Hello Welcome to SRM University" has been successfully executed

course: C ?:.|bject Code:


Q. Addition of numbers(lnteger data type)
Jennys home work for first day is to find addition of two numbers, help jenny to
solve the problem
Source Code
#include<stdio.h>
Int main()
l
int a, b, c;
scanf("%d/<>d", &a, &b);
C = EH-bl
printf("The addition of two number is:/<>d",c);
return 0;
)
Sample Input
6
2
Sample Output
The addition of two number is:8
Result
Thus, Program "Addition of numbers(lnteger data type)" has been successfully
executed

course: C Srbject Code:


Q. DT-6:Division of numbers
Harinis home work for fourth day is to divide two numbers, help Harini to solve the
problem
Source Code
#include<stdio.h>
lnt main()
(
int a. b, c;
scanf("%d %d.&a.&b):
c = a/b;
prlntf("The Division of two number is:%d",c);
return 0;
l
Sample Input
7 2
Sample Output
The Division of two number is:3
Result
Thus, Program " DT-6:Division of numbers" has been successfully executed

course: C Srbject Code:


Q. Float Division of numbers
Harinis home work for fourth day is to divide two numbers, help Harini to solve the
problem
Source Code
#include<stdio.h>
int main()
l
oat a,b,c;
SC8l'lf("/of %f'.&a,&b):
c = a/b;
prlntf("The Division of two number is:%f"__c);
return 0;
l
Sample Input
7.2 3.4
Sample Output
The Division of two number is:2.117647
Result
Thus, Program " Float Division of numbers" has been successfully executed

course: C frbject Code:


Q. Module of numbers
Harinis home work for filth day is to find reminder of two numbers, help Harini to
solve the problem
Source Code
#incIude<stdio.h>
int main()
l
int a. b, c;
scanf("%d%d", &a,&b);
c=a%b;
printf("The modulo of two number is:%d",c);
return 0;
)
Sample Input
6
2
Sample Output
The modulo of two number ls:0
Result
Thus, Program " Module of numbers" has been successfully executed

Subject Code:
Course: C H
Q. Multiplication of numbers
Harinis home work for third day is to multiplication oi two numbers, help Harini to
solve the problem
Source Code
#include<stdio.h>
int main()
i
float d_.e,i;
scanf("%i/of",&d,&e);
f=d'e;
printf("\nThe Multiplication of two number is:%f",f);
print1("\nThe Multiplication oi two number is:%.2f",f);
return 0;
l
Sample Input
7.2
1.5
Sample Output
The Multiplication of two number is:10.799999
The Multiplication of two number is:10.80
Result
Thus, Program " Multiplication of numbers " has been successfully executed

course: C Srbject Code:


Q. Addition of two numbers
Harinis home work for the second day is to subtract two numbers, help Harini to
solve the problem
Source Code
#include<stdlo_h>
lnt main()
l
int a. b, c;
float d.e,l;
//printf("Enter two numbers to add\n");
scanf("%d/<>d",&a,&b);
scanf("%f%f".&d.&e)I
C = a+b:
f=d+e;
printf("The Addition of two number ls:%d\n',c);
printf("The Addition of two number is:%.2t',t);
return O;
l
Sample Input
4
4
5.5
6.4
Sample Output
The Addition of two number ls:8
The Addition of two number ls:11.90
Result
Thus, Program "Addition of two numbers " has been successfully executed

course: C fubject Code:


Q. Modulo of numbers(lnteger data type)
Jennys home work for Fifth day is to nd modulo of two numbers, help jenny to solve
the problem
Source Code
#include<stdio.h>
Int main()
l
int a, b, c;
scanf("%d/<=d".&a,&b);
c = a/obi
printf("The reminder of two number is:%d".c);
return 0;
)
Sample Input
6
2
Sample Output
The reminder of two number is:0
Result
Thus, Program " Modulo of numbers(Integer data type)" has been successfully
executed

Subject Code:
Course: C H
m
Q. Display your na
Write a program to g
Source Code
#incIude <stdio.h>
mt main()
{
char a[20];
scanf("%s",a);
printf("Your name |s:%s
return 0;
l
Sample Input
SRMUniversity
Sample Output
Your name is:SRMUnive
Result
Thus, Program "Dis
e
eta string and print it.
=3);
rsity
play your name" has been successfully executed

Course: C 11
Subject Code:
Q. DT-10: Floa
Write a C prog
Source Code
#include<stdio.h>
int main()
{
int a.b;
float x.y;
scanf("%f",&x)I
scanf("%f",&y);
a = (int)(x+O.5);
b = (int)(y+0.5)2
printf("Value ls:%d",a):
.. .%d..b
printf( \nValue ls.
retum 0;
l
Sample Input
4.6
5.8
Sample Outpu
Value is:5
Value is:6
Result
Thus, Program
t to Integer
t
ram to convert integer to float number.
);
" DT-10: Float to Integer" has been successfully executed

course: C Srbject Code:


Q. DT-11:Celsius To Farenheit
Mercy and her friends went a trip to hill station during winter. It is raining
heavily so they cant go outside. mercy felt very bored and
decided to ask puzzle to her friends. She gave them the temperature in Celsius
format and asked them to convert it to Fahrenheit.
Source Code
#include <stdio.h>
oat temp_f; / degrees tahrenheit '/
oat temp_c; / degrees centigrade /
char line_text[50]: /' a llne of input /
int main() {
fgets(line_text, sizeof(line_text). stdin);
sscanf(llne_text, '/of", &temp_c):
temp_f = ((9.0 / 5.0) ' temp_c) + 32.0;
printf("/of degrees Fahrenheit", temp_f);
return(0):
l
Sample Input
45.0
Sample Output
1 13.000000 degrees Fahrenheit
Result
Thus, Program " DT-11:CeIsius To Farenheit " has been successfully executed

course: C Srbject Code:


Q. DT12: Print date/month/Year
Write a C program to print your name, date of birth. and mobile number.
Source Code
#include <stdio.h>
lnt maIn()
t
char a[20], b[20]I
int date,year.code.number:
scanf('%s",a);
scanf("/>s".b):
scanf("%d",&date);
scanf(%d",&year);
scanf("%d",&code):
scanf("%d',&number);
printf("Name:%s",a);
printf("\nDOB:/<>s %d %d",b,date_year);
printf("\nMobile:%d-%d",code.number);
return 0;
l
Sample Input
SRMUniverslty
March
23
1 991
99
1 234567890
Sample Output
Name:SRMUniversity
DOB:March 23 1991
Mobi|e:99-1234567890
Result
Thus, Program " DT12: Print date/month/Year" has been successfully executed

course: C Srbject Code:


Q. DT14: Print Details
John joined in his new college in chennai. The College is rated as one of the best
private university in India. On first day of his college,
John teacher have asked his personal details for data purposes. Kindly help john to
perform the task using coding. Refer same input
and output for details
Source Code
#lnclude <stdio.h>
int maln()
l
char name[2O]:
int age,yearI
float percentage;
scanf("%s", name);
scanf("%d",&age):
scanf("%f",&percentage):
scanf(%d",&year);
printf("Name:%s",name)I
printf("\nAge:%d",age);
printf("\nPercentage 1/<>f',percentage);
printf("\nYear of Passlng:%d"_year);
return 0;
l
Sample Input
john
21
79.9
2017
Sample Output
Namezjohn
Age:21
Percentage:79.900002
Year of Passlng:2017
Result
Thus, Program " DT14: Print Details" has been successfully executed
course: C Srbject Code:
Q. Conversion on specific
Write a C program to convert specified days into years, weeks and days.
Source Code
#include <stdio.h>
rm ma|n()
{
Int days, years, weeks:
scanf("%d",&days):
// Converts days to years. weeks and days
years = days/365;
weeks = (days % 365)/7;
days = days- ((years'365) + (weeks'7));
printf("Years:%d\n", years);
printf("Weeks:%d\n", weeks);
printf("Days:%d", days);
return 0:
l
Sample Input
3456
Sample Output
Years:9
Weeks:24
Days:3
Result
Thus, Program "Conversion on specific " has been successfully executed

course: C Spbject Code:


Q. Age Calculator
Declare me as an integer. Get two integer values as mentioned in sample input and
output Declare average as a float and assign it the
average of me and you. Then using one printf for each line, print the following.
The numbers are printed using the values of the
variables. The last line starts on a tab position
Source Code
#lnclude <stdio.h>
lnt maln()
l
int a,b;
float c:
scanf("%d /<>d",8-a_&b);
c=(a+b)/2:
printf("l am:%d\nYou are:/<>d\nWe are around:%f'_a.b,c);
return 0;
l
Sample Input
40
20
Sample Output
I am:40
You are:20
We are around:30.000000
Result
Thus, Program " Age Calculator " has been successfully executed
course: C ?:.|bject Code:
Q. Cube of a Number
Write a C program to find the cube of a number
Source Code
#include <stdio.h>
int main()
{
Int a;
scanf("%d,&a);
printf("%d'.aa'a)I
return 0;
l
Sample Input
2
Sample Output
3
Result
Thus, Program "Cube of a Number" has been successfully executed

course: C Spbject Code:


Q. Square of a Number
Write a C program to find the square of a number
Source Code
#include <stdio.h>
int main()
{
Int a;
scanf("%d,&a);
printf("%d'.aa);
return 0;
l
Sample Input
2
Sample Output
4
Result
Thus, Program "Square of a Number" has been successfully executed

course: C Spbject Code:


Q. Subtraction of numbers(lnteger data type)
Jennys home work for Second day is to find subtraction of two numbers, help jenny
to solve the problem
Source Code
#include<stdio.h>
int main()
(
int d,e.f;
scanf("%d %d",&d.&e);
f=d-e:
printf("\nThe Subtraction of two number ls:/<>d"_t):
return 0;
l
Sample Input
6
2
Sample Output
The Subtraction of two number Is:4
Result
Thus, Program "Subtraction of numbers(|nteger data type) " has been successfully
executed

course: C ibject Code:


Q. Multiplication of numbers(lnteger data type)
Jennys home work for Third day is to find Multiplication of two numbers, help jenny
to solve the problem
Source Code
#include<stdio.h>
int main()
l
int d.e.f;
scanf("%d%d",&d,&e);
f=d"e;
printf("\nThe Multiplication of two number is:%d",f);
return 0;
l
Sample Input
6
2
Sample Output
The Multiplication of two number is:12
Result
Thus, Program " Multiplication of numbers(lnteger data type) " has been
successfully executed

course: C Spbject Code:


Q. Division of numbers(lnteger data type)
Jennys home work for Fourth day is to find Division of two numbers, help jenny to
solve the problem
Source Code
#include<stdio.h>
Int main()
(
int a. b, c;
scanf("%d/<>d", &a, &b);
c=a/b;
prIntf("The division of two number ls:%d",c);
return 0;
l
Sample Input
6
2
Sample Output
The division of two number is:3
Result
Thus, Program "Division of numbers(lnteger data type)" has been successfully
executed

course: C Stibject Code:


Q. Substraction of numbers
Harinis home work for second day is to subtract two numbers, help Harini to solve
the problem
Source Code
#include<stdio.h>
int main()
t
oat d.e,f;
scanf("%f %f,&d.&e)I
f=d-e;
printf("\nThe Subtraction of two number Is:%f",t);
printf("\nThe Subtraction of two number is:/<>.2t\n".t);
return 0;
)
Sample Input
7.2
1.5
Sample Output
The Subtraction of two number ls:5.70000O
The Subtraction of two number is:5.70
Result
Thus, Program " Substraction of numbers " has been successfully executed

course: C Srbject Code:


Q. Alice in Wonderland
Alice was bored that day,so she was sitting on the riverbank .Sudden|y she notices
a talking, White Rabbit with a pocket watch .lt ran
fast,and she followed it, down a rabbit hole .She fell into the hole and found a
magical wonderland with dark trees, beautiful flowers.She
found many ways numbered from 1,2,3, ...... ..18.she was confused which is the
right way that will lead her to her home. She found a
cute bird, standing in one of the tree. Alice asked the bird the way to go back to
her home.The bird said a two digit number( say 23 ) and
asked her to find the sum of its digits (2+3=5) and that numbered way will lead her
to her home.Alice was already confused, so pls help
Alice in finding the route to her home.... lnput Format: Input consists of an
integer corresponding to the 2-digit number. Output Format:
Output consists of an integer corresponding to the sum of its digits. Refer sample
input and output for formatting specifications
Source Code
#lnclude<stdio.h>
Int maln()
l
lnt a,b.c.d;
scanf("%d".&a)1
b=a/10;
c=a/010;
d=b+C:
if(a>99)
printf("\nnot a 2 digit number\n");
else
printf("\nA|ice must go in path-%d".d);
retum 0:
l
Sample Input
23
Sample Output
Alice must go in path-5
Result
Thus, Program " Alice in Wonderland " has been successfully executed

course: C Spbject Code:


Q. Average Scale
A grocer has a scale of Rs. S1,Rs . S2, Rs. S3 ,Rs. S4 and Rs. S5 for 5 consecutive
months. How much sale must he have in the sixth
month so that he gets an average sale for Rs.X? Write a C program to compute the
sale in the 6th Format: Input format: Input consists
of 5 integers and 1 oat. The five integers corresponds to s1 ,s2,s3,s4,s5. The
float input corresponds to x.
Source Code
#include<stdio.h>
int maln()(
float a,b_.c;
scanf("/<>f",&a);
$C8f("/of", &b);
c=a-((b'a)/100);
printf("The selllng price of the cycle ls Rs=%.2f\n",c);
retum 0:
l
Sample Input
1400 15
Sample Output
The selling price of the cycle is Rs=1 190.00
Result
Thus, Program " Average Scale " has been successfully executed

Course: C Srbject Code:


Q. AVERAGE SALE
A grocer has a sale of Rs. s1, Rs. s2, Rs. s3, Rs. s4 and Rs. s5 for 5 consecutive
months. How much sale must he have in the sixth
month so that he gets an average sale of Rs. x? Write a C program to compute the
sale in the 6th month. lnput Format: Input consists of
5 integers and 1 float. The ve integers correspond to s1, s2, s3, s4 and s5. The
float input corresponds to x. Output Format: Refer
sample input and output for formatting specifications. The float values are
displayed correct to 2 decimal places
Source Code
#lnclude <stdio.h>
int maln()
l
Int s.a,b,c,d,e;
float x,f;
scanf("%d',&a);
scanf(/>d",&b);
scanf("%cl",&c);
scanf("%d",&d);
scanf("/ed".&e);
scanf("%f",&x):
s=(a+b+c+d+e);
f=(6'x)-s;
printf("The required sale in the sixth month is %.2f", f);
retum O;
l
Sample Input
64:-as 6927 sass 7230 6562 7000.0
Sample Output
The required sale in the sixth month ls 7991.00
Result
Thus, Program " AVERAGE SALE" has been successfully executed

course: C Silbject Code:


Q. Calculating SP
A man buys a cycle for Rs. a and sells it at a loss of b%. What is the selling
price of the cycle? Write a C program to compute the selling
price. input Format: The first input is an integer which corresponds to a. The
second input is an integer which corresponds to b.
Source Code
#include<stdlo.h>
lnt maln()(
oat a.b.c;
scanf("/cf",&a);
scanfU%zfL&by
c=a((b'a)/100);
printf(The selling price of the cycle is Rs=%.2f".c);
retum O:
)
Sample Input
1400
15
Sample Output
The selling price of the cycle ls Fts=1 190.00
Result
Thus, Program " Calculating SP" has been successfully executed

course: C Srbject Code:


Q. Calculating Gain Percentage
Vikram buys an old scooter for Rs. A and spends Rs. B on its repairs. If he sells
the scooter for Rs. C , what is his gain %? Write a C
program to compute the gain %. Input Format: The first input is an integer which
corresponds to A. The second input is an integer which
corresponds to B. The third input is a oat which corresponds to selling price
Source Code
#lnclude<stdlo.h>
lnt main()(
float a.b,c.d,e;
scant("%f",&a);
scanf("/of", &b);
scant("%t",&c);
d=8+bI
e=((c-d)rd)'100;
printt("The gain percentage is=%.2t".e):
retum 0:
)
Sample Input
4700
aoo
5800
Sample Output
The gain percentage is=5.45
Result
Thus, Program " Calculating Gain Percentage" has been successfully executed

course: C Srbject Code:


Q. Calculating Percentage
SRM University buys an old scooter for Rs. A and Spends Rs. B on its repairs. if he
sells the scooter for Rs.C , what is his gain %? Write
C program to compute the gain %? Input format: The first input is an integer which
corresponds to A . The second input is an integer
which corresponds to B. The third input is a float which corresponds to gain %
Source Code
#include<stdio.h>
int main()(
float a,b,c,d,e:
scanf("/<>f",&a);
scanf("%f", &b);
scanf("%f",&c):
d=a-Pb:
e=((c~d)/d)'100;
printf("The gain percentage is=%.2f".e);
retum O:
)
Sample Input
4700 aoo saoo
Sample Output
The gain percentage is=5.45
Result
Thus, Program " Calculating Percentage" has been successfully executed

course: C Subject Code:


Q. Calculating SP
A man buys a cycle for Rs. A and sells its a loss of B% . What is the selling price
of the cycle? Write a C program to compute the selling
price Input format: The first input is an integer which corresponds to A . The
second input is an integer which corresponds to B.
Source Code
#include<stdlo.h>
lnt maln()(
oat a,b.c;
scanf("/cf",&a);
scanf("/cf", &b);
c=a-((b'a)/100);
printf("The selling price of the cycle ls Fls=/c.2f',c);
retum 0;
)
Sample Input
1400
15
Sample Output
The selling price of the cycle ls Rs=1 190.00
Result
Thus, Program " Calculating SP" has been successfully executed
course: C Srbject Code:
Q. Computing X
The cost prince of n articles is the same as the selling price of X articles . If
the profit is p% then what is the value of x? lnput format:
The first input is an integer which corresponds to n the second is an integer which
corresponds to p Output Formt: Refer sample Input
and output for formatting Specifications The float values are displayed correct to
2 decimal places.
Source Code
#lncIude<stdlo.h>
int maln()(
float a.b,x;
oat c,d;
scanf("/of", &a);
scanf("%t",&b);
c=(b'0.01);
d=C+1 I
X=a."d;
printf("The value of X ls=%.2f".x):
retum 0;
l
Sample Input
12.5
14.5
Sample Output
The value of x ls=10.92
Result
Thus, Program " Computing X " has been successfully executed

Course: C Srbject Code:


Q. FENCING THE GROUND
The college ground is rectangular in shape. The Management decides to build a fence
around the ground. ln order to help the
construction workers to build a straight fence, they planned to place a thick rope
around the ground. They wanted to buy only the exact
length of the rope that is needed. They also wanted to cover the entire ground with
a thick carpet during rainy season. They wanted to
buy only the exact quantity of carpet that is needed. They requested your help. Can
you please help them by writing a C program to tind
the exact length of the rope and the exact quantity of carper that is required?
Input Format: Input consists of 2 integers. The first integer
corresponds to the length of the ground and the second integer corresponds to the
breadth of the ground.
Source Code
#|nclude<stdio.h>
Int main()
(
int Length,Width,|en,quan;
scanf("/<>d".&Length);
scant("%d'.&W|dth);
len=2(Length+Width);
quan=Length'Wldth;
printi("Required length is %clm".len);
printf("\nRequired quantity of carpet is %dsqm".quan):
retum 0:
l
Sample Input
so 20
Sample Output
Required length is 140m
Required quantity of carpet is 1000sqm
Result
Thus, Program " FENCING THE GROUND" has been successfully executed

course: C Srbject Code:


Q. Finding bitwise AND of two numbers
Write a program to find the bitwise AND of two decimal numbers. An AND gate reads 2
input either 0 or 1 and outputs 1 i both the
inputs are 1. Similarly write a program to read two decimal numbers and finds AND
of two numbers . EXAMPLE : (3)10 = (011)2 (5)10 =
(101)2 AND of 3 and 4 is : (1)10 = (001)2
Source Code
#include<stdio.h>
lnt main()
l
lnt a,b.c;
scanf('%d",&a):
scanf("%d'.&b)1
c=a&b:
printf("Bitwise AND of /od and %d is:%d".a__b,c);
retum 0:
l
Sample Input
12 23
Sample Output
Bitwise AND of 12 and 23 is:4
Result
Thus, Program " Finding bitwise AND of two numbers" has been successfully executed

course: C Spbject Code:


Q. Finding bitwise EXOR of two numbers
Write a program to find the bitwise EXOR of two decimal numbers. An EXOR gate reads
2 input either 0 or 1 and outputs 0 if both the
inputs are same and outputs 1 if both the inputs are different. Similarly write a
program to read two decimal numbers and finds EXOR of
two numbers. EXAMPLE 1 (3) 10 = (011) 2 (5) 10 = (101) 2 EXOR of 3 and 4 is : (6)
10 = (110) 2
Source Code
#include<stdio.h>
lnt main()
l
lnt a,b.c;
scanf("%d".&a);
scanf("%d".&b)l
c=a"b;
printf("Bitwise EX-OR of %d and %d is=/<>d".a,b.c):
retum 0:
l
Sample Input
12
23
Sample Output
Bitwise EX-OR of 12 and 23 is=27
Result
Thus, Program " Finding bitwise EXOR of two numbers" has been successfully executed

course: C Srbject Code:


Q. Finding OR of two numbers
Write a program to find the bitwise OR of two decimal numbers. An OR gate reads 2
input either 0 or 1 and outputs 0 iff both the inputs
are 0 else 1. Similarly write a program to read two decimal numbers and finds OR of
two numbers . EXAMPLE : (3) 10 = (011) 2 (5) 10 =
(101) 2 OR 013 and 4 is : (7) 10 = (111) 2
Source Code
#include<stdio.h>
lnt main()
l
int a,b.c;
scanf("%d".&a);
scanf("/<>d".&b):
c=alb;
printf("Bltwlse OR of %d and %d is:%d",a,b.c);
retum O:
l
Sample Input
12 23
Sample Output
Bitwise OR of 12 and 23 is:31
Result
Thus, Program " Finding OR of two numbers " has been successfully executed

course: C Srbject Code:


Q. Finding OR of two numbers
Write a program to find the bitwise OR of two decimal numbers. An OR gate reads 2
input either 0 or 1 and outputs 0 iff both the inputs
are 0 else 1. Similarly write a program to read two decimal numbers and finds OR of
two numbers . EXAMPLE : (3) 10 = (011) 2 (5) 10 =
(101) 2 OR 013 and 4 is : (7) 10 = (111) 2
Source Code
#include<stdio.h>
lnt main()
l
lnt a,b.c;
scant("%d".&a);
scanf("%d".&b)l
C=alb:
printf("Bitwise OR of %d and %d is=%d".a.b.c):
retum 0:
l
Sample Input
12
23
Sample Output
Bitwise on of 12 and 23 is=31
Result
Thus, Program " Finding OR of two numbers " has been successfully executed

Course: C Spbject Code:


Q. Find Mode
Write a program to find the mode of a given list of integers. Mode of a number is
defined as the number which is most frequently
occurred. For example. L = {1,2,2,3} // Here mode is 2(most frequently occurred) lt
is possible that multiple answers are possible for a
list. In that case pnnt all possible answers in non-increasing order lnput' First
Line of input contains an lnte er t re resent th
. . g p ing e
number of test cases, Where first line of each test case has an integers N - number
of integers in list, Next line contains N integers.
Output: print all the possible modes in non-increasing order. Constraints:
1<=t<=100 1<=N<100000 1<=a[i]<=1000000
Source Code
#lnclude<stdlo.h>
#deflne max(a. b) (((a) >= (b)) ? (a) : (b))
lnt maln()(
int t, n, no, i; scanf("%d", &t);
whlle(t-- && scanf("%d", &n)){
int h[1000001] = {O}, m1 = 1. m2 = 0;
while(n-- && scanf("%d", &no)) h[no]++, m1 = max(m1_ no);
for(i = 1; I <= m1: l++) m2 = max(m2, h[l]);
for(i = m1; i >= 1; i--) if(h[l] == m2) printf("%d I);
printf("\n');
l
return 0;
l
Sample Input
25122226122334
Sample Output
2
32
Result
Thus, Program "Find Mode " has been successfully executed

course: C Spbject Code:


Q. Find Remainder
Write a program to find the remainder when two given numbers are divided. Input The
first line contains an integer T, total number of
test cases. Then follow T lines, each line contains two Integers A and B. Output
Find remainder when A is divided by B. Constraints 1 ?
T? 10001 ?A,B ? 10000
Source Code
#include<stdio.h>
maln()
l
int t:
scanf("%d".&t);
while(t--)
l
int a,b.c;
scanf("%d /od, &a,&b);
c=a%b2
printt("Remainder is %d\n",c);
l
l
Sample Input
3
1 2
100 200
10 40
Sample Output
Remainder is 1
Remainder ls 100
Remainder is 10
Result
Thus, Program "Find Remainder " has been successfully executed

course: C Sjibject Code:


Q. FOUR SEASONERS
Dinesh also joined the group of 3 idiots and now their group is called Four
Seasoners. Meanwhile, Binoy has moved to a new house in
the same locality. Now the houses of Ajay, Binoy and Chandru are in the located in
the shape of a triangle. Dinesh also has moved to a
house in the same locality. When Ajay asked Dinesh about the location of his
house , Dinesh said that his house is equidistant from the
houses of the other 3. Though Ajay was good in Mathematics, he was puzzled. Can you
please help Ajay out? Given the 3 vertices
{(x1,y1), (x2,y2) and (x3,y3)} of a triangle, write a C program to determine the
point which is equidistant from all the 3 vertices. Input
Format: Input consists of 6 integers. The first integer corresponds to x1 . The
second integer corresponds to y1. The third and fourth
integers correspond to x2 and y2 respectively. The fifth and sixth integers
correspond to x3 and y3 respectively.
Source Code
#lnclude<stdlo.h>
lnt maln()
l
int X1 ,X2.X3,Y1 .Y2.Y3;
oat a_b;
scanf("%d",&X1);
scanf("%d"_&Y1);
scanf("%d".&X2);
scanf("%d".&Y2);
scanf("%d".&X3);
scanf("%d".&Y3):
a=(X1+X2+X3)/3.0:
b=(Y1+Y2+Y3)/3.0:
printf("Dlnesh house is located at (%.1f.%.1f)\n".a.b);
retum 0;
l
Sample Input
2 4
10 15
5 8
Sample Output
Dinesh house is located at (S.7,9.0)
Result
Thus, Program " FOUR SEASONERS " has been successfully executed
Q Grade The Steel
A certain grad
one condition
of steel is graded according to the following conditions. Hardness must be greater
than 50 Carbon content must be less
than 0.7. 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
course: C Subject Code:
e
conditions (i) and (ii) are met. Grade is 8 if conditions (ii) and (m) are met.
Grade is 7 if conditions (i) and (m) are met Grade is 6 if only
is
met. Grade is 5 if none of three conditions are met. Write a program, if the user
gives values of hardness, carbon
content and tensile strength of the steel under consideration and display the grade
of the steel.
Source Code
#include<stdlo.h>
maln()
l
lnt t:
scanf("%d",&t);
while(t--)
t
Int hardness, ts,
oat carbon:
.. %
scanf( /od %f
grade;
d, &hardness,&carbon,&ts);
if ((hardness>50) && (carbon<0.7) && (ts>5600))
printf("Grade 1O\n");
else if ((hardness>50) && (carbon<0.7))
printf(Grade 9\n");
else if ((carbon<0.7) && (ts>5600))
printf("Grade 8\n");
else if ((hardness>50) && (ts>5600))
printf("Grade 7\n");
else if ((hardness>50) || (carbon<0.7) || (ts>5600))
printf("Grade 6\n");
else
printf("Grade 5\n");
l
l
Sample Input
2
53 0.7 5602
55 0 5499
Sample Outpu
Grade 10
Grade 9
Result
Thus, Program
t
" Grade The Steel " has been successfully executed
course: C Srbject Code:
Q. Greedy puppy
Tuzik is a little dog. But despite the fact he is still a puppy he already knows
about the pretty things that coins are. He knows that for
every coin he can get very tasty bone from his master. He believes that some day he
will find a treasure and have loads of bones. And
nally he found something interesting. A wooden chest containing N coins! But as
you should remember, Tuzik is just a little dog, and so
he cant open it by himself. Actually, the only thing he can really do is barking.
He can use his barking to attract nearby people and seek
their help. He can set the loudness of his barking very precisely, and therefore
you can assume that he can choose to call any number of
people, from a minimum of 1, to a maximum of K. When people come and open the chest
they divide all the coins between them in such
a way that everyone will get the same amount of coins and this amount is maximal
possible. If some coins are not used they will leave it
on the ground and Tuzik will take them after they go away. Since Tuzik is clearly
not a fool, he understands that his profit depends on
the number of people he will call. While Tuzik works on his barking, you have to
find the maximum possible number of coins he can get.
Input The first line of the input contains an integer T denoting the number of test
cases. Each of next T lines contains 2 space-separated
integers: N and K, for this test case. Output For each test case output one integer
- the maximum possible number of coins Tuzik can
get. Constraints 1 ? T ? 50 1 ? N, K ? 105 In the first example he should call two
people. Each of them will take 2 coins and they will
leave 1 coin for Tuzik. ln the second example he should call 3 people
Source Code
#include<stdlo.h>
int main()
(
lnt t,m,n;
scanf("%d",&t);
while(t--)
(
int ma = 0;
scanf("/<>d%d"_.&m,8.n);
int ii
for(i=2;i<=n;i++)
lt([m/oi )> ma)ma = m%l;
printf("%d\n",ma):
l
retum 0:
l
Sample Input
2
52
113
Sample Output
1
2
Result
Thus, Program " Greedy puppy " has been successfully executed

course: C Spbject Code:


Q. Multiplication for a child
Jeyanthi daughter name is Han'ni, she was studying 1st Standard in a school.
Harinis home work for the third day is to Multiplication of
two numbers, help Harini to solve the problem.
Source Code
#include<std|o.h>
Int maln()
l
oat a,b.c;
scant("%f", &a);
scanf("%f, &b):
c=ab;
printf("multipIication of the two numbers is /.2f",c);
retum O;
)
Sample Input
12
10
Sample Output
multiplication of the two numbers is 120.00
Result
Thus, Program "Multiplication for a child has been successfully executed

course: C Subject Code:


Q. PLACING THE FLAG POST
The shape of the college ground is Square. For the Independence day Flag Hoisting
Function, it has been decided to place the flag post
at the exact center of the ground. Can you please help them in placing the flag
post at the exact center? Given the coordinates of the
left bottom vertex of the square ground and the length of the side, you need to
write a program to determine the coordinates of the
centre of the ground. [Assumption Length of the side is always even] Input Format:
input consists of 3 integers. The first integer
corresponds to the x-coordinate of the left bottom vertex. The second integer
corresponds to the y-coordinate of the left bottom vertex.
The third integer corresponds to the length of the square.
Source Code
#include<stdio.h>
int main()(
int x,y,l;
scanf("%d",&x];
scanf("%d",&y);
scanf("%d".&l):
x=x+(l/'2);
Y=y+(|/'2);
printf("centre of the ground is at(%d.%d)",x,y);
retum 0:
l
Sample Input
4 0 a
Sample Output
centre of the ground is at(8,4)
Result
Thus, Program " PLACING THE FLAG POST " has been successfully executed

course: C Spbject Code:


Q. Pogo Stick Jump
Raju lives in a colony. On his 9th birthday, his father gift him a Pogo Stick. He
is so excited to play with pogo stick. The pogo stick
moves one unit per jump. He wanders around his house jumping with pogo sticks. He
wants to show the pogo stick to his friends and
decide to go using pogo sticks. Write a program to find number of jumps needed to
reach his friends house. Assume that Rajus house is
in the location (3,4). Input and Output Format: Input consists of two integers x,
y. The x and y corresponds to x and y coordinates of his
friends house. Output is an integer - the number of jumps he needs to reach his
friends house.
Source Code
#lnclude<stdlo.h>
#include<math.h>
int maln()
f
lnt x1 =3,y1 =4,x2.y2;
oat power.power1.power2,sqr;
scanf("%d",&x2);
scanf("%d",&y2);
power1=pow((x2-x1 ),2);
power2=pow((y2-y1),2);
power=p0wer1 +power2;
sqr=sqrt(power);
printf("Raju needs %.0f jumps",sqr):
retum 0:
l
Sample Input
5 6
Sample Output
Raju needs 3 jumps
Result
Thus, Program " Pogo Stick Jump " has been successfully executed

course: C Srbject Code:


Q. PROFIT CALCULATOR
Each Sunday, a newspaper agency sells x copies of a certain newspaper for Rs.a per
copy. The cost to the agency of each newspaper
is Rs.b . The agency pays a fixed cost for storage, delivery and so on of Fts.100
per Sunday. The newspaper agency wants to calculate
the profit obtained on Sundays. Can you please help them out by writing a C program
to compute the profit given x, a and b. Input
Format: Input consists of 3 integers x, a and b. X is the number of copies sold, a
is the cost per copy and b is the cost the agency
spends per copy.
Source Code
#|nclude<stdio.h>
lnt main()
l
lnt c0ples,cost.spent,profitjinalprot;
scanf("%d",&copies);
scanf("%d".&cost):
scanf("%d",&spent);
profit=((copies'cost)-(copiesspent));
finalproflt=(prot)-100;
printf("The profit obtained is Rs=/>d\n".fina|proflt);
it(finalprofit==-100)
printf("invalid input"):
retum O:
l
Sample Input
1000
2
1
Sample Output
The profit obtained is Rs=9OO
Result
Thus, Program PROFIT CALCULATOR " has been successfully executed

Course: C Srbject Code:


Q. Radius of a Circle
Madhan is handling mathematics to 8th grade. He taught area and perimeter of
geometric shapes to his students. He thought to give a
test based on triangle and circles.The task is to calculate radius of the circle
that is inscribed in triangle given the three sides of the
triangle. He has set 20 questions and he is tired of preparing answer keys.Write a
program to find the radius of the circle inscribed in a
triangle. Input and Output Format : Input consists of three integers a, b and c.
The three integer corresponds to three sides of a triangle
Source Code
#lnclude<stdlo.h>
#include<math.h>
int maln()
(
int a.b,c;
float s,rsq,r;
scanf("/od\n,&a);
scanf("%d\n",&b)I
scant("%d".&c);
s=(a+b+c)!2;
rsq=((s-a)'(s-b)'(s-c)/s);
r=sqrt(rsq);
printf("The radius of the clrcle is=%.2f\n",r);
retum 0;
)
Sample Input
3 4 5
Sample Output
The radius of the circle is=1.00
Result
Thus, Program " Radius of a Circle" has been successfully executed

course: C Szibject Code:


Q. Scanning Int and string by retailer
Haris retail shop he need a software to get the name of the product and cost of the
product and generate a bill for that one product
which consist of name of the product and cost of that product.
Source Code
#include<stdIo.h>
Int maln()
l
char ch[20];
lnt a;
scanf("/<>s".ch);
scanf("%d",&a)I
printf("PRODUCT NAME:/<>s"_ch):
printt("\nCOST:%d",a):
retum O;
l
Sample Input
soap
121
Sample Output
PRODUCT NAME:soap
COSTI121
Result
Thus, Program "Scanning Int and string by retailer" has been successfully executed

course: C Srbject Code:


Q. Splitting into Teams
During the Physical Education hour, PT sir has decided to conduct some team games.
He wants to split the students in the class into
equal sized teams. In some cases, there may be some students who are left out from
teams and he wanted to use the left out students
to assist him in conducting the team games. For instance, if there are 50 students
in the class and if the class has to be divided into 7
equal sized teams, 7 students will be there in each team and 1 student will be left
out. PT sir asks your help to automate this team
splitting task. Can you please help him out? Input Format: Input consists of 2
integers. The first integer corresponds to the number of
students in the class and the second integer corresponds to the number of teams.
Source Code
#include<stdio.h>
Int main()
l
Int students.teams.team,left:
scanf("/<>d".&students);
scanf("%d'.&teams);
feam=students1teams;
left=students/>teams:
printf("The number of students in each team is /od and left out is %d".team.left);
retum 0:
l
Sample Input
60
8
Sample Output
The number of students in each team is 7 and left out is 4
Result
Thus, Program " Splitting into Teams" has been successfully executed

81
Q Finding St
A certain grad
one condition
of steel is graded according to the following conditions. Hardness must be greater
than 50 Carbon content must be less
than 0.7. 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
course: C Srbject Cod
. ' ' ee
e
conditions (i) and (ii) are met. Grade is 8 if conditions (ii) and (m) are met.
Grade is 7 if conditions (i) and (m) are met Grade is 6 if only
is
I Grade
met. Grade is 5 if none of three conditions are met. Write a program, if the user
gives values of hardness, carbon
content and tensile strength of the steel under consideration and display the grade
of the steel.
Source Code
#include<stdlo.h>
maln()
l
lnt t:
scanf("%d",&t);
while(t--)
l
Int hardness, ts,
oat carbon:
.. %
scanf( %d %f
grade;
d, &hardness,&carbon,&ts);
ll ((hardness>50) && (carbon<0.7) && (ts>5600))
printf("Grade 1O\n");
else if ((hardness>50) && (carbon<0.7))
printf(Grade 9\n");
else if ((carbon<0.7) && (ts>5600))
printf("Grade 8\n");
else if ((hardness>50) && (ts>5600))
printf("Grade 7\n");
else if ((hardness>50) || (carbon<0.7) || (ts>5600))
printf("Grade 6\n");
else
printf("Grade 5\n");
l
l
Sample Input
2
53 0.7 5602
55 0 5499
Sample Outpu
Grade 10
Grade 9
Result
Thus, Program
t
" Finding Steel Grade" has been successfully executed

course: C Spbject Code:


Q. Summing the N series
You are given a sequence whose nth nth term is Tn=n2<(n<=1)2Tn<=n2<=(n<=1)2 You
have to evaluate the series Sn=T1+T2+T3+
<=+TnSn=T1+T2+T3+<=+Tn Find Snmod(109+7)Snmod(109+7). Input Format The first line
of input contains TT, the number of test
cases. Each test case consists of one line containing a single integer nn. Output
Format For each test case, print the required answer in
a line. Constraints 1<=T<=101<=T<=10 1<=n<=1O"161<=n<=10"16
Source Code
#inc|ude <stdio.h>
#lnclude <string.h>
#include <math.h>
#include <stdlib.h>
#lnclude <tgmath.h>
int main() {
int cases;
scanf("/ed. &cases);
lnt i;
for (i=O:i<cases:i++){
long int nthterm;
scanf("%ld", &nthterm);
long long int modulo = pow(10, 9) + 7;
printf("%lld\n". (long long int)powl((nthterm % modulo) .2%modulo)/omodulo) 1
l
retum 0;
l
Sample Input
2
21
Sample Output
4
1
Result
Thus, Program " Summing the N series" has been successfully executed

course: C Srbject Code:


Q. Sum of palindromic numbers
A number is called palindromic if its decimal representation is a palindrome. You
are given a range, described by a pair of integers L and
R. Find the sum of all palindromic numbers lying in the range [L, R], inclusive of
both the extrema. Input The first line of the input
contains an integer T denoting the number of test cases. The description of T test
cases follows. The first line of each test case contains
a pair of space separated integers L and R denoting the range for which you are
required to find the sum of the palindromic numbers.
Output For each test case, output a single line containing the sum of all the
palindromic numbers in the given range. Constraints
1<=T<=100 Subtask 1 (34 points) : 1<=L<=R<=f03 Subtask 2 (66 points) : 1<=L<=Fk=105
Explanation Example case 1. The
palindromic numbers between 1 and 10 are all numbers except the number 10. Their
sum is 45.
Source Code
#lnclude <stdio.h>
lnt maln()
l
int t;
scanf("%d",&t):
while(l--)
l
lnt a,b;
scanf("%d /<>d",&a,&b);
int i; long int s=0;
for(i=a;i<=b;i++)
l
lnt reverse=0, rem,temp=i;
whl|e(templ=0)
{
rem=temp%1O;
reverse=reverse' 1 0+ rem;
temp/=10;
l
if(reverse==i) s+=l1
}
printf("sum ls />ld\n",s);
l
return 0;
l
Sample Input
2
1 10
123 150
Sample Output
sum is 45
sum ls 272
Result
Thus, Program " Sum of palindromic numbers " has been successfully executed

course: C Srbject Code


Q. THREE IDIOTS
Ajay, Binoy and Chandru were very close fnends at school They were very good |n
Mathematlcs and they were the pet students of
Emily Mam. Therr gang was known as 3-ldlots Ajay, Bmoy and Chandru l|ve |n the same
localrty A new student Dmesh |o|ns the|r class
and he wanted to be fnends w|th them He asked Bmoy about has house address Bmoy
wanted to test Dmeshs mathematlcal skrlls
Binoy told Dinesh that h|s house |s at the m|dpo|nt of the l|ne ]OlllIt'lg Ajays
house and Chandrus house Dmesh was puzzled Can you
help Dinesh out? Gwen the coordlnates of the 2 end pomts of a lme (x1,y1) and (x2
y2), wr|te a C program to fmd the mldpomt of the
line. Input Format Input consusts of 4 mtegers The flrst Integer corresponds to x1
The second Integer corresponds to y1 The thrrd and
fourth integers correspond to x2 and y2 respectlvely
Source Code
#|nclude<stdlo.h>
rm maln()
f
lnt X1 ,X2,Y1 .Y2;
float m1.m2,m3;
scanf("%d',&X1);
scanf("%d",&Y1 );
scanf("/<>d",&X2);
scanf("%d".&Y2);
m1=(X1+X2)/2.0;
m3=Y1+Y2;
m2=m3/2;
printf("\nBinoys house ls located at(/> 1f /0 1f) mf m2)
retum 0:
l
Sample Input
24
1015
Sample Output
Binoys house is located at(6 0 9 5)
Result
Thus, Program " THREE IDlOTS" has been successfully executed

course: C Srbject Code:


Q. Lucy
Lucy is celebrating her 15th birthday. Her father promised her that he will buy her
a new computer on her birthday it she solves the
question asked by him. He asks Lucy to nd whether the year on which she had born
is leap year or not. Help her to solve this puzzle so
that she celebrates her birthday happily. If her birth year is 2016 and it is a
leap year display 2016 is a leap year.? Else display 2016 is
not a leap year and check with other leap year conditions
Source Code
#lnclude <stdio.h>
lnt maln()
l
Int year;
//printf("Enter a year to check if it is a leap year\n');
scanf("%d', &year);
If ( year%40O == 0)
prlntf(%d is a leap year. year);
else it ( year/@100 == 0)
printi("%d is not a leap year", year);
else ii ( year%4 == 0 )
printf("/>d is a leap year. year);
else
printf("%d is not a leap year", year);
retum O:
l
Sample Input
1900
Sample Output
1900 is not a leap year
Result
Thus, Program " Lucy " has been successfully executed

Course: C Spbject Code:


Q. Biased Chandan
Chandan is an extremely biased person, and he dislikes people who fail to solve all
the problems in the interview he takes for hiring
people. There are n people on a day who came to be interviewed by Chandan. Chandan
rates every candidate from 0 to 10. He has to
output the total ratings of all the people who came in a day. But, heres the
problem: Chandan gets extremely frustrated when someone
ends up scoring a 0 in the interview. So in frustration he ends up removing the
candidate who scored that 0, and also removes the
candidate who came before him. If there is no candidate before the one who scores a
0, he does nothing.Youve to find the summation
of all the ratings in a day for Chandan. Input constraints: The first line of input
will contain an integer n. The next n lines will contain an
integer, where the ith integer represents the rating of the ith person. Output
constraints: Print the required sum. Constraints: 1 <= n <= 5
103 0 <= Value of ratings <=1 0
Source Code
#incIude <stdio.h>
int maln()
i
int n,i,sum=O:
scanf("%d".&n)1
int a[n]:
for(i=0;i<n;l++)
(scanf("%d",&a[i]);)
ll(n==1){printf("%d",a[0]);}
lf(n>1)(
for(i=1;i<n;l++)
(lf(aFl==0)
(Int j=l;
while(a[i]==0)
ll=i-1 ll
alll=01}
l
for(i=0:i<n;l++)
sum=sum+a[l];
printf("%d",sum);
l
retum 0:
l
Sample Input
O\JOOO|\JU'l
Sample Output
2
Result
Thus, Program " Biased Chandan" has been successfully executed

course: C Srbject Code:


Q. Doll Show
In London, Every year during Dasara there will be a very grand doll show. People
try to invent new new dolls of different varieties. The
best sold dolls creator will be awarded with cash prize . So people broke their
head to create dolls innovativeiy .Knowing this
competition, Mr. LokPaul tried to create a doll which sings only when a even number
is pressed and the number should not be zero and
greater than 100. So write a C program to help mr. Lokpaul to win. Input format:
lnput consists of 1 integer which corresponds to
Number pressed by the user to the doll. Output format : Display whether the doll
will a sing or not. Output consists of the string "Doll will
sing" or "Invalid number" Refer sample input and output for further formatting
specifications.
Source Code
#lnclude<stdio.h>
Int main()(
lnt x;
char a[20]='Doll will sing'.b[20]="lnvalld Number";
scanf("%d",&x);
if(x<100 && x%2==0 && xl=0)
{
prinlf("%s\n",a);
I
else
{
plllllT("/o$\l'l",D)
)
return 0;
}
Sample Input
56
Sample Output
Doll will sing
Result
Thus, Program " Doll Show " has been successfully executed

Course: C ?;.lb]8Cl Code:


Q. Leap year
Raghuraman is the worrisome as well as caring father of his only daughter
bharani ,together they live a calm and content life. Over the
years as Bharani grows up , Raghuramam got more and more attached to his daughter
bharani. As bijarani is very intelligent and bright
in her studies. She got a good placement offer in canada. Raghuraman was
shocked.Although the thought of being separated from his
dead daughter is heartbreaking. Raghuraman wearily accepts. Bharani promises her
that she will come home once every leap year.
Raghuraman was waiting for his daughter arrival. He doesnt know which is leap year.
So write a C program to help Flaghumaran to find
a whether the year is a leap year. Input format: Input consists of single integer
which corresponds to a year Output format 1 Displays
whether the given year is a leap year or not. Refer sample input and output for
further formatting specifications.
Source Code
#lnclude <stdio.h>
int maln()
t
Int a:
//printf("Enter a year to check if it is a leap year\n");
scanf('/ad", &a);
if ((a%4==0)&&((a%100l=0)][(a%400==0)))
l
printf("Leap Year");
}
else
l
printf("Not a Leap year");
}
retum O:
l
Sample Input
2004
Sample Output
Leap Year
Result
Thus, Program "Leap year " has been successfully executed
course: C Spbject Code:
Q. Approximate Value
Phineas and Ferb who live in the fictional town of danville ,think and do
innovatively on weekends. Every day the boys embark on some
grand new project, which annoys their controlling sister candace, who tries to bust
them. One sunday they were both sitting under a tree
in their back yard. They decide to invent a machine which would allow us to enter 2
numbers it would say whether one of the entered
number is an appropriate value of the other number entered. They decide to insert a
program code in the machine. A number is said to
be an approximate value of the other if they differ by utmost 0.5. So write a C
program to find whether the given number is approximate
number of other. Input Format: Input consists of two float type numbers Output
format: Displays whether the number is approximate or
not.
Source Code
#lnclude<stdio.h>
Int maln()(
int x.y,c;
scanf("%d/od',&x_&y):
if(y>X)
I
c=y-x;
I
else
I
c=x-y;
1
lf(c<=0.5)
{
printf("ApproxImate number");
)
GISG
I
prinlf("Not an Approximate number");
1
return 0;
)
Sample Input
14
14.3
Sample Output
Approximate number
Result
Thus, Program " Approximate Value " has been successfully executed

course: C Srbject Code:


Q. A Task
A task is given to 3 persons to complete it within a particular time. If the person
exceeds the time limit he will be disqualified . Only those
who complete it within the given time limit is qualied. Among the qualified
persons. the person who complete the task first will be
rewarded. Write C program to find the person who is rewarded.Write a C program to
find the person who is rewarded. Input Format:
First Input corresponds to the time limit for the task in hours . Second, third and
fourth input corresponds to the number of hours taken
by the first, second and third persons respectively to complete the task. Output
format: Display the person who completes first.
Source Code
#lnclude<stdlo.h>
int main()(
int a,b,c,d;
scanf("/>d/<>d%d%d",&a,&b,&c,&d);
lf(b<a&&c>b&&d>b)
l
printf("Flrst person winsll");
l
else if(c<a&&b>c&&d>c)
l
prinff("Second person wlnsll);
l
else if(d<a&&b>d&&c<d)
l
prlntf("Third person winsll);
l
else if(b>a&&c>a&&d>a)
l
printf("No person winsll");
l
return 0:
l
Sample Input
\lJ>U'\*
O
Sample Output
Second person winsll
Result
Thus, Program " A Task " has been successfully executed

course: C Srbject Code:


Q. Blood Bank
A team from SRM Rotaract club had planned to conduct rally to create awareness
among the chennai people to denote blood. They
conducted the rally successfully. Many of the chennai people realise it and came
fonrvard to donate their blood to near by blood bank.
The eligibility criteria for donating blood is people should be above 18 and his
her weight should be above 40. There was a huge crowd
and staff in blood bank found it difficult to manage the crowd. So they decided to
keep a system and ask the people to enter their age
and weigh in a system. If a person is eligible he /she will be allowed inside.
Write a C program and feed it to the system to find whether a
person is eligible or not. Input format: Input consists of 2 integers which
corresponds to age and weight of a person respectively. Output
Format: Display whether person is eligible or not.
Source Code
#lnclude<stdlo.h>
Int maln()(
int x_y;
scant("/<>d",&x);
scanf("%d',&y);
it(x>18&&y>40)
{
printf("Eligible to donate");
}
else
{
prlntt("Not Eligible to donate");
l
return 0;
l
Sample Input
19
50
Sample Output
Eligible to donate
Result
Thus, Program " Blood Bank" has been successfully executed

course: C Spbject Code:


Q. Chef and Balls
Chef has bought ten balls of five colours. There are two balls of each colour.
Balls of same colour have same weight. Let us enumerate
colours by numbers from 1 to 5. Chef knows that all balls, except two (of same
colour), weigh exactly one kilogram. He also knows that
each of these two balls is exactly 1 kg heavier than other balls.You need to find
the colour which balls are heavier than others. To do
that, you can use mechanical scales with two weighing pans. As your scales are very
accurate, you can know the exact difference of
weights of objects from first and second pans. Formally, the scales will give you
the difference (signed difference) of weights of the
objects put into the first pan and the second pan. See the following examples for
details If you put two balls of the same colour on your
scales, each ball to one pan, the scales will tell you that difference is "0". But
if you put into the first pan some balls of total weight 3 kg,
and into the second pan of 5 kg, then scales will tell you because the second pan
is 2 kg heavier than first Similarly, if you put 5 kg
weight in first pan and 3 kg in the second pan, then scale will tell you "2" as
first pan is 2 kg heavier than second. Input & Output The
interaction process have two phases. At first phase you perform sequence of
weighings on the mechanical scales. At the second phase
you should output the colour of the heavier balls To use the mechanical scales, you
should print "1"(without quotes) and then print two
lines, the first line will describe the enumeration of colours of balls on the
first pan and second line should that of second pan To
describe some pan, you need to print one integer n - the number of balls you put in
this pan, followed by n space-separated integers -
colours of the balls you put in this pan Once you have printed required data, you
can read from the standard input one integer - the
difference of weights of the first and the second pans To output the colour of the
heavier balls, you should print "2"(without quotes) and
one integer in next line - colour of the heavier balls. Constraints Each colour you
print should be between 1 and 5.
Source Code
#lnclude<stdlo.h>
int main()
f
int x;
printf("1\n");
fflush(stdout);
prlntf("3 1 2 2\n");
fflush(stdout);
prlntf('3 3 4 4\n);
fflush(stdout);
scanf(%d",&x):
printf("2\n");
fflush(stdout);
if(x==0)
{
printf("5)1
fflush(stdout);
}
else lf(x==1)
l
printf("1");
fflush(stdout);
l
else lf(x==2)
l
printf("2"):
fflush(stdout);
}
else |f(X=='1)
l
PYi""("3");
fflush(stdout);
}
e|$e |f(X==-2)
i
printf("4"):
fflush(stdout);
}
return 0;
l
Sample Input
1
Sample Output
1
3122
3344
2
1
Result
Thus, Program " Chef and Balls " has been successfully executed

course: C Strbject Code:


Q. Pattern 1
Write a program to generate a following structure: @@@@@ @@@@@ @@@@@ @@@@@ @@@@@
Source Code
#include<stdlo.h>
lnt maln()
t
int num.r,c;
//printf("Enter loop repeat number(rows): ");
scanf('%d",&num);
for(r=1: num>=r: r++)
{
for(c=1; c<=num: c++)
prinm"@">;
printt("\n):
}
return 0;
l
Sample Input
2
Sample Output
@@
@@
Result
Thus, Program " Pattem 1 " has been successfully executed

course: C Spbject Code:


Q. Pattern 2
Write a program to generate a following #s triangle: # # # # # # # # # # # # # # #
Source Code
#include<stdio.n>
lnt maln()
l
int num.r=1,c,sp;
//printf("Enter loop repeat number(rows): ")1
scanf('%d",&num);
for(: num>=1: num--,r++)
l
for(sp=r; sp>1: sp--)
P"""(" "ll
for(c=1; c<=num; c++)
printf("#");
printf("\n');
l
return 0;
l
Sample Input
s
Sample Output
#####
##4##
###
##
#
Result
Thus, Program " Pattem 2 " has been successfully executed

course: C Sgbject Code:


Q. Pattern 3
Write a program to generate a following @s triangle: @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
Source Code
#include<stdio.h>
int main()
{
int num.c:
//printf("Enter loop repeat number(rows): ")1
scanf('%d",&num);
for(I num>=1: num--)
{
for(c=1: c<=num: c++)
pr1nm"@">;
printf("\n'):
}
return 0;
i
Sample Input
7
Sample Output
@@@@@@@
@@@@@@
@@@@@
@@@@
@@@
@@
@
Result
Thus, Program " Pattem 3 " has been successfully executed

course: C fubject Code:


Q. Pattern 4
Write a program to generate a following #s triangIe:- # # # # # # # # # # # # # # #
Source Code
#inc|ude<stdio.h>
Int main()
{
int num.r,c;
//printf("Enter loop repeat number(rows): ")1
soanf('%d",&num);
for(r=1: num>=r: r++)
{
for(c=1: c<=r; c++)
pn'ntf("#"):
printf("\n"):
}
return 0;
)
Sample Input
3
Sample Output
#
##
###
Result
Thus, Program " Pattem 4 " has been successfully executed

course: C Srbject Code:


Q. In/out
Ms.Kirthiga, the faculty handling programming lab for you is very strict. Your
seniors have told you that she will not allow you to enter the
weeks lab if you have not completed atleast half the number of problems given last
week. Many of you didnt understand this statement
and so they requested the good programmers from your batch to write a c program to
find whether a student will be allowed into a week
lab given the number of problems given last week and the number of problem solved
by the students in that week. lnput format: lnput
consists of 2 integers. The First integer corresponds to the number of problems
given and the second integer corresponds to the
number of problems solved. Output format: Output consists of the string "lN" or
"OUT" Refer sample input and output for further
formatting specifications.
Source Code
#lnclude<stdlo.h>
lnt maln()(
int x.y.z;
char a[2O]="lN",b[20]="OUT";
scanf("/<>d/>d,&x.&y);
z=x/2:
if(y>z)
{
printf("%s\n".a);
}
else
{
prlnlt("%s\n".b);
l
return 0;
l
Sample lnput
8
3
Sample Output
OUT
Result
Thus, Program " In/out " has been successfully executed

Course: C 11
Subject Code:
Q. Pattern 5
Write a program to generate a following @s triangle: @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
Source Code
#include<stdio.h>
int main()
l
int num.r,c,sp;
//printt("Enter loop repeat number(rows): ")1
scanf('%d",&num);
for(r=1: num>=r: r+
{
+>
for(sp=num-r: sp>=1: sp--)
prin(" "1:
for(c=1: c<=r; c++)
prmm"@">;
printt("\n');
}
return 0;
l
Sample Input
5
Sample Output
@
@@
@@@
@@@@
@@@@@
Result
Thus, Program "
Pattem 5 " has been successfully executed

course: C rbject Code:


Q. Pattern 6
Write a program to generate a following numbers structure
Source Code
#include<stdlo_h>
lnt maln()
l
int num.r,c;
//print1("Enter loop repeat number(rows): ");
scanf(%d",&num);
for(r=1: num>=r; r++)
{
for(c=1; c<=num; c++)
prlntf("%d".c);
printf("\n");
l
return 0;
l
Sample Input
5
Sample Output
12345
12345
12345
12345
12345
Result
Thus, Program " Pattem 6 " has been successfully executed

course: C Srbject Code:


Q. Better or Not
One criteria for evaluating 2 different colleges is based on the student strength.
Write a C program to compare 2 colleges based on the
student strength Input fonnat: Input consists of 2 integers. The first integer
corresponds to the Number of students during the year of
establishment of college 1 and the second integer corresponds to the Number of
students during the year of establishment of college 2
Output format: Output consists of the string "College 1 is Better" or "College 2 is
Better". Refer sample input and output for further
formatting specifications.
Source Code
#|nclude<stdlo.h>
lnt main()(
int x_y;
char a[20]='College 1 is better".b[2O]="Co|lege 2 is better;
scanf("%d/=d",&x.&y);
if(y>x)
{
prlntf("/<>s\n".b);
l
else
{
prIntf("%s\n",a);
l
return 0;
l
Sample Input
1 000
1200
Sample Output
College 2 is better
Result
Thus, Program " Better or Not " has been successfully executed

course: C Srbject Code:


Q. New or Old
When parents take their kids for Engineering Counselling , they always go with a
preconceived notion that older the college, better will
be the quality of education offered. There is a help desk in front of the
counselling hall to tell out of the colleges in which seats are
available., which college is the older one. Now a days ,engineering counselling
goes on for a month and the help desk need to function
on all days. So the Dean, Admissions decided to automate this task. Can you help
him in this task? Given the year of establishment of 2
colleges , write a C program to determine which colleges is the older one. Input
format: Input consists of 2 integers. The first integer
corresponds to the year of establishment of college 1 and the second integer
corresponds to the year of establishment of college 2
Output format: Output consists of the string "College 1 is older" or "College 2 is
older". Refer sample input and output for further
formatting specifications.
Source Code
#lnclude<stdlo.h>
int main()(
int x.y;
char a[20]="College 1 is older".b[20]="College 2 ls older":
scanf(%d%d',&x,&y);
if(x<y)
l
prlnff("%s-.n".a);
l
else
l
prinff("%s\n",b);
i
return 02
l
Sample Input
2002
2008
Sample Output
College 1 is older
Result
Thus, Program " New or Old " has been successfully executed
course: C Spbject Code:
Q. Semester Holidays
Normally in all engineering colleges, there will be long vacation after every even
semester and a short vacation after every odd
semester. Input format: Input consists of 1 integers which corresponds to the
current semester of the students (i.e) Even semester "
Long Vacation" ODD semester "Short Vacation" determine by dividing(modulo) with 2
Output format: Output consists of the string "Long
Vacation " or "Short Vacation". Refer sample input and output for further
formatting specifications.
Source Code
#lnclude<stdlo.h>
Int ma|n()(
int x.y:
scanf("%d",&x);
y=x%2:
if<y==0>
{
prlntf("Long Vacatlon");
l
else
l
printf("Short Vacation"):
l
return 0;
l
Sample Input
6
Sample Output
Long Vacation
Result
Thus, Program " Semester Holidays " has been successfully executed

Course: C Spbject Code:


Q. Lab seating arrangement
There are 2 Programming Labs . Each with a seating capacity of 90. There are 240
students with registration numbers from 1 to 240. All
240 students cannot be accommodated in the labs at the same time. It has been
decided to conduct theory class for 60 students every
week. It has been planned to conduct theory classes for all students with register
number being a multiple of 4. Students with
registration number from to 1 to 120 with registration number not a multiple of 4
need to be seated in programming lab1 and students
with registration numbers from 121 to 240 with registration numbers not a multiple
of 4 need to be seated in programming lab ll. Given
the registration number of student, write a C program to specify the lab or hall in
which student need to be seated. Input Format: Input
consists of 1 integer which corresponds to the registration number of the student.
Output format: Output consists of string "Lab 1" or
"Lab 2" or "Theory session " or ?lncorrect Register Number? Refer sample input and
output for further formatting specifications.
Source Code
#include<stdio.h>
lnt maln()(
int x.y;
scant("%d",&x);
if((X/o4==O)&&(X<=240))
{
prlntf("Theory session");
l
else if (((x>=1)&&(x<12O))&&(x%4l=0))
{
prlntf("Lab 1");
l
else if(((x>=120 )&& (x<=240))&& (x/<>4l=0))
{
prlntf("Lab 2");
l
else
{
prln11("lncorrect Register Number"):
l
return 0:
}
Sample Input
16
Sample Output
Theory session
Result
Thus, Program "Lab seating arrangement" has been successfully executed

course: C Srbject Code:


Q. Sections
If the number of seats allowed to a particular branch in engineering exceeds 60,
then where will be multiple sections in that branch.
Given the number of seats allotted to a branch write a C program to determine
whether there will be a single section or multiple sections
Input Format: Input consists of 1 integer which corresponds to the number of seats
allotted to a branch Output format: Output consists of
string "Single sections" or "Multiple Sections" Refer sample input and output for
further formatting specifications.
Source Code
#lnclude<stdio.h>
int maln()(
int xi
scanf("%d",&x);
it(x<=60)
l
printf("S|ngle Sections");
l
else
{
prlntf("MultIple Sections);
}
retum O;
)
Sample Input
72
Sample Output
Multiple Sections
Result
Thus, Program " Sections " has been successfully executed

course: C Spbject Code:


Q. Class Representative
A student is eligible to be a class representative if his or her attendance % and
marks is greater that 90% and he or she doesnt have
any arrears. Given the attendance % ,mark /<> and number of arrears, write a C
program to determine whether a student is eligible to be
a Class Representative or not. input format: input consists of 2 float and an
integer. The first float corresponds to the attendance /<> and
the second float corresponds to the percentage of marks. The third input is an
integer which corresponds to the number of arrears.
Output format : Output consists of the string "Eligible " or "Not Eligible" Refer
sample input and output for further formatting
specifications.
Source Code
#lnclude<stdio.h>
Int main()(
float a,b;
int c;
scanf("%f",&a);
scanf("%f",&b)I
scanf(/>d",&c);
lf(a>90&&b>9O &&c==0)
l
prlntf("Ellgible);
i
else
{
printf("Not Eligible");
}
return 0:
i
Sample Input
100.0
96.3
0
Sample Output
Eligible
Result
Thus, Program Class Representative " has been successfully executed

Course: C Srbject Code:


Q. Mickey Mouse
Mickey and Miney are two friends . Goofy was one of the mickey enemy . He was
jealous of mickey because mickey was liked by
everyone. One day mickey and miney went on to a trip. Goofy planned to kidnap
miney. He kidnapped miney and kept her in one of the
hot balloons tied up to a height. there where 50 hot balloons numbered from one.
Each balloons will y to a certain height. Only the
numbers having 3 and 7 as its factors can fly upto the height of the miney balloon.
mickey was confused and he didnt know which
numbered balloon can fly to miney. So write a program to help the mickey in finding
the balloon. Input format: Input consists of Single
Integer which corresponds to number printed on the balloon. Assume that the input
value is between 1 and 50 Output format : Display
whether the given Balloon will fly to Miney or Not Refer sample input and output
for further formatting specications.
Source Code
#lnclude<stdio.h>
int maln()(
int x;
scanf("%d",&x);
lf((x/o3==0)&&(x%7==O))
{
printf("This balloon can fly to miney");
}
else
l
prlntf("This balloon cannot fly to miney");
I
return 0;
l
Sample Input
24
Sample Output
This balloon cannot fly to miney
Result
Thus, Program " Mickey Mouse has been successfully executed

course: C Szibject Code:


Q. Palindrome count - String Count
Given a string S, count the number of non empty sub strings that are palindromes A
sub string is any continuous se uence of
- q
characters in the string. A string is said to be palindrome, if the reverse of the
string is same as itself. Two sub strings are different if
th . . . . . . . .
ey occur at different positions in S Input Input contains only a single line that
contains string S. Output Print a single number, the
number of count in the string. Constraints 1 <= |S| <= 50 S contains only lower
case latin letters, that is characters a to z.
Source Code
#lnclude<stdio.h>
int maln()
l
lnt n,l,j,|;
char str[51];
long int dp[51][51];
scant("%s",str);
n=O;
for(|=0:str[i]l="\0':i++)
n++;
for(l=O:i<n-1:i++)
dp[i+1][i]=0;
tor(i=0;kn:i++)
dP[illi]=1 ;
f0|'(|=1;kllZ|++)
l
for(i=0;kn-l:i++)
l
j=i+l;
if(sfr[i]==str[j])
dP[illll=dPlilll-11+dPli+1]ll]+1 ;
else
dP['1[il=dP[i1U-1]+dPli+1]U]*1P[|+1H1411
l
l
prlntf("Number of palindromic substrings:%ld",dp[0][n~1]);
return 0;
l
Sample Input
WELCOMETOSRMUNIVERSITY
Sample Output
Number of palindromic substrings:14t
Result
Thus, Program " Palindrome count - String Count" has been successfully executed

course: C Srbject Code:


Q. Game of Strings
Harsh and Akshara are playing the Game of Strings. This game is a simple one and is
played as a team. Both the players of a team will
be given a string respectively. At the end of this game, every team is required
find out the length of the longest string S such that the
strings given to each of the team members is a subsequence of S andS contains no
vowels. Help Harsh and Akshara in finding out the
required length. Input: Input consists of a single line containing two space
separated strings. Output: The length of the longest string that
satisfy the given conditions. Constraints: 1 ? length of string ? 5000 Explanation
The required string is "ng". if the constraint of the string
S not containing vowels is removed, this becomes the classical Longest Common
Subsequence (LCS) problem. For readers who are
not familiar with LCS problem, they are encouraged to go through the following link
which explains the problem as well to how to come
up with the solution.
http://en.wikipedia.org/wiki/Longest_common_subsequence_problem One can see that
the LCS of the input two
strings can never contain any vowels, hence, it is redundant to have vowels in the
original string. Now, if we remove the vowels from the
input strings, the problem is to find the length of the LCS of the edited strings.
One can use the same approach described in the above
wiki link to implement the solution.
Source Code
#lnclude <stdio.h>
#deflne MAX_N 5000+1
char str1[MAX_N];
char str2[MAX_N];
int str1Len, str2Len;
#define MAX(A,B) ((A)>(B)?(A):(B))
int DPArr{MAX_N][MAX_N]:
int cStrLen(char str1)
l
int i=0;
while(str1 [i] l= '\0')
l++;
return ll
l
int lsVowel(char c)
(
int res = 0:
"(( == 'a' ll <= == 'e' ll <= == 'i' ll c = '0' ll <= =='u'> 1|
(c == A || c == '5' || <; == '|' || == -0' || =='u'))
res = 1;
return res
l
int runDP(int len1, int len2)
i
int i,j;
int max =0:
for(l=0: i<|en1+1; i++)
DPArr[l][0] = 0;
for(l=0: i<|en2+1: i++]
DPArr[0][i] = 0;
for( i=1; i<(len1+1): i++)
{
for( j=1: ]<(len2+1); j++)
i
if(str1 U-1] l= str2[j-1])
DPArr[i][]] = MAX(DPArr[i-1][j]. DPArr[l][j-1]):
else if(lsV0wel(str1[i-11))
DPArr[|][_|] = MAX(DPArr[l-1][j], DPArr{l][|-1]);
else
l
DPArr[i]|j] = DPArr[i-1][j-1] + 1;
}
l
i
#lt 0
pr|ntf("\n "):
for( i=0; i<(|en2); l++)
l
printf("%c ", str2[i]);
}
prlntf("\n )1
for( i=0; i<(len1+1): i++)
{
lf(l>=1)
prlntf("%c ", str1[l-1]):
for( i=0: j<(len2+1); j++)
{pl'll"Itf("/ed ", DPArr[i][j]);
zmmr("\n'):
flendif
return DPArr[|en1][len2];
i
int maln()
(
scanf('%s". str1 );
scanf("%s". str2);
strt Len = cStrLen(str1);
str2Len = cStrLen(str2):
printf("%d", runDP(str1 Len. str2Len));
return 0;
l
Sample Input
HDDS 3.8DbSS
Sample Output
3
Result
Thus, Program "Game of Strings " has been successfully executed

Subject Code:
Q. Sum of Eve
Write a progra
to n, the size of
Output Format
Source Code
#include<stdio.h>
#include<stdl|b.h>
Int "createArray(int
Course: C 11
m
n numbers
to nd the sum of even numbers in an array. Input Format: Input consists of n+1
integers. The first integer corresponds
the array. The next n integers correspond to the elements in the array. Assume that
the maximum value of n is 15.
Refer sample output for details.
void getElement(int
lnt sumofArray(|nt
lnt maln()
i
lnt "a,b.n1
scant("%d",&n);
a=createArray(n);
getElement(a,n);
b=sumotArray(a,n)
printf("The sum of
retum O;
l
lnt createArray(in
{
int a;
a=(int ')malloc(n'si
retum a;
l
void getElement(ln
i
lnt i.
for(l=0;i<n;i++)
i
scant("%d",a+i);
l
l
int sumofArray(int
(
lnt sum=0,l;
forU=0j<n++)
(
lt('(a+i)%2==0)
(
sum=sum+(a+i);
l
l
FGIUYH SUITII
l
Sample input
5
2368-1
Sample Outpu
The sum of the ev
Result
Thus, Program
Q
)1
',int);
Int);
the even numbers in the array is:%d",b);
t n)
zeot(int));
t
t 'a,int n)
'a.|nt n)
en numbers In the array is:16
" Sum of Even numbers " has been successfully executed

Subject Code:
Q. Sum of eve
Write a progra
corresponds to
value of n is 15
Source Code
#lnclude<stdlo.h>
#include<stdlib.h>
Int createArray(int
void getElement(in
void sumofArray(ln
int maln()
l
int a,n;
scanf("%d',&n);
a=createArray(n);
getE|ement(a,n);
sumofArray(a,n);
retum O;
l
int 'createArray(in
l
int a;
a=(lnt )malIoc(n'sl
retum a:
l
Course: C H
m
?n? , the size of the array. The next ?n? integers correspond to the elements in
the array. Assume that the maximum
):
t',int);
t,lnt)2
n and odd numbers
to find the sum of even and odd numbers in an array. Input Format: Input consists
of n+1 integers. The first integer
Output Format: Refer sample output for details.
tn)
ze0f(lnt));
void getElement(int 'a,int n)
(
int ii
f0l(i=0Ii<liZi++)
l
scanf("%d",a+i);
l
l
nt
void sumofArray(i
l
int i.sum1=0.sum2
for(i=0;i<n;i++)
l
if('(a+i)%2==0)
l
sum1=sum1+'(a+i
l
else
i
sum2=sum2+'(a+
l
l
printf("The sum of
printf(The sum of
l
Sample Input
5
2368-1
Sample Outpu
)1
i);
t
a.Int n)
=0;
the even numbers in the array is:/<>d\n",sum1);
the odd numbers In the array ls:%d,sum2)2
The sum of the even numbers in the array is:16
The sum of the od
Result
Thus, Program
d numbers in the array is:2
" Sum of even and odd numbers" has been successfully executed

Course: C Spbject Code:


Q. Compare 2 arrays
Write a program to find whether 2 arrays are the same. Input Format: Input consists
of 2n+1 integers. The first integer corresponds to ?
n? , the size of the array. The next ?n? integers correspond to the elements in the
rst array. The next ?n? integers correspond to the
elements in the second array.Assume that the maximum value of n is 15. Output
Format: Print yes if the 2 arrays are the same. Print no
if the 2 an'ays are different.
Source Code
#|nclude<stdl0.h>
#lnclude<stdl|b.h>
lnt 'createArray(int);
void getElement1 (int '.int);
void getElement2(int ,int);
void checkArray(int ',int ,int);
lnt main()
t
int a,"b,n;
scanf("%d'.&n);
a=createArray(n):
b=createArray(n):
getE|ement1(a,n);
getEiement2(b.n);
checkArray[a,b,n);
retum 0;
l
int "createArray(lnt n)
t
lnt at
a=(int ')malloc(n's|zeof(lnt));
retum a:
l
void getElement1 (int 'a,int n)
l
int i2
f0r(l=02i<n2l++)
(
SC8l1T("/od',3+l)
l
l
void getElement2(int b,int n)
l
int i;
for(i=0:i<n:i++)
i
scanf("%d".b+i);
)
l
void checkArray(int a,int 'b,Int n)
l
int I.c=0;
for(l=0:i<n;l++)
l
//'printf("a+i=%d\n".(a+i));
//'p|'inIf("b+i=/od\I\".(b+i));
"(((a+il)==((b+i)))
t
C++;
l
)
if(c==n)
f
prlntf("yes");
{else
(
printf("no");
l
l
Sample Input
s
23684
23684
Sample Output
yes
Result
Thus, Program " Compare 2 arrays " has been successfully executed

course: C Srbject Code:


Q. Inversion Count
Write a program to find the inversion count of an array. Inversion Count for an
array indicates how far (or close) the array is from being
sorted. if array is already sorted then inversion count is 0. If array is sorted in
reverse order that inversion count is the maximum.
Formally speaking, two elements a[i] and a[i] form an inversion if a[i] > a[i] and
i <j Example: The sequence 2, 4, 1, 3, 5 has three
inversions (2, 1), (4, 1), (4, 3). lnput and Output Format: Input consists of n+1
integers where n corresponds to the number of elements
in the array. The first integer corresponds to n and the next n integers correspond
to the elements in the array. Output consists of a
single integer which corresponds to the number of inversions in an array. Assume
that the maximum number of elements in the array is
20. Refer sample input and output for formatting specifications. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#lnclude<stdio.h>
#lnclude<stdllb.h>
int createArray(int);
void getElement(int ',int);
void inversionCount(lnt ',lnt);
int maln()
l
int a,n;
//printf("Enter the number of elements in the array\n");
scanf("/<>d".&n)2
a=createArray(n):
getElement(a.n);
lnversionCount(a.n);
//printf("The inversion count of the array ls %d,b);
retum 0;
l
int createArray(int n)
t
int a;
a=(lnt )malloc(n'slzeof(lnt));
retum a:
l
void getElement(int 'a_.int n)
t
int i:
//printf("Enter the elements in the arraytn");
for(l=0;i<n;l++)
(
scanf("%d',a+i):
l
l
void inverslonCount(int 'a,int n)
l
int l,c=0,j;
for(i=0;i<n-1;i++)
l
for(j=i+1;]<n;j++)
(
lf('(a+l)>(a+j))
l
c++;
l
l
l
printf("The inversion count of the array lSI/od',C)j
l
Sample Input
5
24135
Sample Output
The inversion count of the array ls:3
Result
Thus, Program " Inversion Count" has been successfully executed

Course: C Spbject Code:


Q. Array Insertion and sorting
Write a program to insert an element in the array. Example For example consider an
array having three elements in it initially and a[O] =
1, a[1] = 2 and a[2] = 3 and you want to insert a number 45 at location 1 i.e. a[O]
= 45, so we have to move elements one step below so
after insertion a[1] = 1 , and a[2] = 2 and a[3] = 3. Input and Output Format:
Assume that the maximum number of elements in the array
is 20. Refer sample input and output for formatting specifications. All text in
bold corresponds to input and the rest corresponds to
output.
Source Code
#|nclude<stdlo.h>
#lnclude<stdlib.h>
int createArray(int);
void getElement(int ',int];
void insertlon(int ',int);
lnt main()
i
Int n.'a;
//printf("Enter the number of elements in the array\n");
scanf("/<>d".&n)I
a=createArray(n):
getElement(a.n);
insertion(a,n);
retum 0:
l
lnt createArray(int n)
l
lnt a;
a=(lnt ')mal|oc(n'slzeot(int));
retum a;
l
void getElement(int 'a.int n)
l
Int i:
//printt("Enter the elements in the array\n");
for(l=0;i<n;l++)
i
scanf("%d".a+i);
l
l
void insertlon(int a.lnt n)
l
int Lpos;
//printf("Enter the location where you wish to insert an element'\n");
scant("%d".&pos);
for(l=n-1;i>=0;l--)
(
(a+l+1)='(a+i);
"(I==pOS-1)
l
I/printf("Enter the value to insert\n');
scanf("%d".a+i);
break;
l
l
ll(pos>n)
i
print1("lnvalid Input);
retum;
l
printf("Array after insertion is\n");
for(l=0:i<n+1;i++)
l
printf("%d\n" .'(a+i));
)
l
Sample Input
5
12345
4
10
Sample Output
Array after insertion is
1
2
3
U1-Ii-l
O
Result
Thus, Program " Array Insertion and sorting" has been successfully executed

Course: C Srbject Code:


Q. Array Deletion
Write a program to delete an element from the array. input and Output Format:
Assume that the maximum number of elements in the
array is 20. Refer sample input and output for formatting specifications. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#inciude<stdio.h>
#include<stdi|b.h>
int 'createArray(int);
void getElement(int ',int);
void deieteElement(int ,int);
int maln()
i
int a,n;
//printf("Enter the number of elements in the array\n");
scanf("%d".&n);
a=createArray(n);
getEiement(a,n);
deleteEiement(a,n);
retum 0;
i
int 'createArray(int n)
l
int a;
a=(int )mailoc(n'size0f(int));
retum a;
i
void getElement(int 'a,int n)
l
int l:
//printt("Enter the elements in the array\n");
forU=0<nn++)
l
scanf("%d'.a+i):
l
i
void deleteElement(int a.int n)
l
int i,pos:
//printf("Enter the location where you wish to delete an eiement\n"):
scanf("%d.&pos);
for(i=0;i<n;i++)
i
if(pos-1==i)
i
for(i=pos-1;i<n:i++)
i
(a+i)='(a+|+1);
i
break:
l
if(pos>n)
( printf('lnvalid input");
retum;
l
}
prlntf("Array after deletion ism");
for(i=0;i<n-1;i++)
( printf("%d\n',(a+l)):
i
}
Sample input
5
12345
4
Sample Output
Array after deletion is
1
2
U103
Result
Thus, Program " Array Deletion " has been successfully executed

course: C Srbject Code:


Q. Array Mean
Write a program to find the mean of the elements in the array. Input and Output
Format: lnput consists of n+1 integers where n
corresponds to the number of elements in the array. The first integer corresponds
to n and the next n integers correspond to the
elements in the array. Output consists of a double value which corresponds to the
mean of the array. It is printed upto 2 digits of
precision. Assume that the maximum number of elements in the array is 20. Refer
sample input and output for formatting specications
All text in bold corresponds to input and the rest corresponds to output.
Source Code
#|nclude<stdlo.h>
#include<stdllb.h>
int "createArray(int);
void getElement(lnt ',lnt);
void arrayMean(int ,int):
lnt maln()
(
lnt 'a.n;
/rprintf("Enter the number of elements in the array\n");
scant("%d".&n);
a=createArray(n):
getElement(a,n);
arrayMean(a,n):
retum 0:
)
Int 'createArray(int n)
l
lnt a;
a=(|nt *)malIoc(n'slzeol(int));
retum a;
l
void getElement(int a.int n)
t
Int it
//printt("Enter the elements in the array\n");
for(i=0:i<n;l++)
l
scant("%d".a+i);
l
l
void an'ayMean(int *a,lnt n)
l
lnt I:
oat add=0.0.add2,mul;
for(i=0;i<n;l++)
l
add2='(a+i)+add;
add=add21
l
mul=add/n;
printf("The mean of the array is %.2f",mul);
l
Sample Input
5
24135
Sample Output
The mean of the array ls 3.00
Result
Thus, Program "Array Mean " has been successfully executed

Course: C Srbject Code:


Q. Array Mean
Write a program to find the mean of the elements in the array. Input and Output
Format: lnput consists of n+1 integers where n
corresponds to the number of elements in the array. The first integer corresponds
to n and the next n integers correspond to the
elements in the array. Output consists of a double value which corresponds to the
mean of the array. lt is printed upto 2 digits of
precision. Assume that the maximum number of elements in the array is 20. Refer
sample input and output for formatting specifications
All text in bold corresponds to input and the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
#lnclude<stdlib.h>
int createArray(int);
void getElement(int ',tnt];
void arrayMean(int ,int):
lnt main()
l
Int 'a,n;
//printf("Enter the number of elements in the array\n");
scanf("/<>d".&n)I
a=createArray(n):
getElement(a.n);
arrayMean(a,n):
retum 0:
l
lnt createArray(int n)
l
lnt a;
a=(lnt ')malloc(n'slzeof(int));
retum a;
l
void getElement(int 'a.int n)
l
Int |
//printf("Enter the elements in the array\n");
for(l=0;i<n;l++)
l
scant("%d".a+i);
l
l
void arrayMean(lnt *a,lnt n)
l
int l:
oat add=0.0.add2,mul;
for(i=0;i<n:l++)
i
add2='(a+i)+add;
add=add2Z
l
mul=add/n;
prlntf("The mean of the array ls %.2t",mu|);
l
Sample Input
U100-*~l\J(J'l
Sample Output
The mean of the array ls 3.00
Result
Thus, Program " Array Mean " has been successfully executed

course: C Srbject Code:


Q. Array Range
Write a program to find the range of the elements in the array. Range of an array
is the difference between the maximum and minimum
element in an array, input and Output Format: Input consists of n+1 integers where
n corresponds to the number of elements in the
array. The first integer corresponds to n and the next n integers correspond to the
elements in the array. Output consists of an integer
which corresponds to the range of the array. Assume that the maximum number of
elements in the array is 20. Refer sample input and
output for formatting specifications. All text in bold corresponds to input and the
rest corresponds to output.
Source Code
#include<stdto.h>
#lnclude<stdlib.h>
int createArray(int);
void getElement(int ',int);
void arrayRange(int ',int);
lnt main()
l
int 'a,n;
//printf("Enter the number of elements in the array\n");
scanf("%d'.&n)3
a=createArray(n):
getElement(a.n);
arrayRange(a,n);
retum 0:
l
lnt 'oreateArray(int n)
l
int "a;
a=(|nt ')mal|oc(n'slzeof(int));
retum a;
l
void getElement(int 'a.int n)
l
Int I:
//printf("Enter the elements in the array\n");
for(i=0;i<n;l++)
(
scanf("/d",a+i);
l
l
void arrayRange(int 'a.int n)
int l,j,temp=O,d;
for(i=0:i<n-1;i++)
or(j=i+1 ;j<n:j++)
f('(a+j)<'(a+i))
emp=(a+i);
(a+l)='(a+j);
'(a+j)=temp;
l
l
l
d=a[n-1]-a[0]:
printf("The range of the array is:%d".d);
l
Sample Input
5
12435
Sample Output
The range of the array ls:4
Result
Thus, Program " Array Range" has been successfully executed

course: C Spbject Code:


Q. Magic Sq
A magic squ
and the num
matrix is a m
rows/column
first row first, then second row and so on. Assume that the maximum value of m and
n is 5. Output Format: Print yes if it is a magic
square. Prin
m
Source Cod
#lnclude<stdlo
#lnclude<stdllb.
Int "createArr
U378
are is an arrangement of numbers (usually integers) in a square grid, where the
numbers in each row, and in each column,
bers in the fowvard and backward main diagonals, all add up to the same number
Write a program to find whether a given
agic square or not. Input Format: The input consists of (n"n+1) integers. The first
integer corresponds to the number of
s in the matrix. The remaining integers correspond to the elements in the matrix.
The elements are read in rowwise order,
t no if it is not a magic square
9
h>
h>
(int)'
ay ,
void getEleme s(int",lnt);
void magicsqu
int maln()
i
int a,n;
are(int*,int);
scant("/<>d".&n);
a=createArray(
getElements(a,
maglcSquare(a,
retum 0;
l
int createArr
QY
l
int "a,l;
a=(int")mal|oc(
for(l=0;kn;l++)
(
'(a+l)=(int ')ma|
l
retum a;
l
void getEleme
nt
l
Int i,j;
for(l=0;i<n;l++)
l
for(j=0:]<n;]++)
l
scanf("%d".'(a
l
l
l
void magicSqu
l
int l,j,sum=0,su
sum=0;
for(l=0;i<n;i++)
l
sum=0;
for(}=0;]<n;j++)
l
sum=sum+('(
l
sum2=sum;
n):
H);
n):
(int n)
nsizeof(int));
loc(nsizeof(lnt'));
s(int "a.lnt n)
+i)+j)I
are(lnt "a,lnt n)
m1 =0,r=O,c=0.sum2,sum3,sum4,sum5;
3+i)+]);
if(sum1==sum)
(
r++;
l
sum1=sum;
l
if(r!=n-1 8-& su
l
printf("n0")I
retum:
l
printf("\n");
sum1 =0;
for(j=0:j<n:j++)
l
sum=0;
for(i=0;i<n;l++)
l
sum=sum+('(
l

(a*|]+l))3
it(sum1==sum)
l
c++;
i
sum1=sum;
l
sum3=sum:
/1
I/printf("sum3
if(c|=n-1&&sum
(
printf("no");
retum;
l
sumt =0;
sum=0;
for(l=0:kn;l++)
l
for(j=0:j<n:]++)
(
lf(i==i)
(
sum.-.sum+'('(
l
l
l
sum4=sum'
/fprintf( sum4
" %d
sum=0;
sum1 =0;
for(l=0;i<n;l++)
l
for(|=0;j<n;]++)
l
sum=sum+('(
break;
l
sum1=sumZ
i
sum5=sum;
//printf("sum5
/
if(sum4==sum5
(
lf((sum2==sum
l
printf["yes\n');
l
l
else
(
printf("no\n");
retum;
l
l
Sample lnp
2
45
54
Sample Ou
(IO
Result
Thus, Progr
d\n',sum3);
l=0)
a+i)+j);
\n',sum4);
a+i)+j);
<>d\n",sum5);
)
3)&&(sum3==sum4)&&(sum2==sum4))
ut
tput
am " Magic Square" has been successfully executed

course: C Spbject Code:


Q. Class Homework
Ramesh and Suresh were in the same class and got home work from their mathematics
teacher. The Homework consists of N strings
and each string consists of only digits. The task which they need to perform is
that they need to divide the string into 4 integers such that
their sum is maximum. Note: Each integer should be <= 1012 and should not contain
any leading zeroes. As we know that Suresh and
Ramesh are weak in mathematics and also they dont want to be punished. So, they
need your help for finding the answer. INPUT: First
line contains an integer N denoting the number of strings. Next N lines contain N
strings each consists of digits only. OUTPUT: For each
test case, Print the required answer it exists. Print "unlucky" otherwise.
CONSTRAINTS: 1<=N<=104 1<=size of each string ? 20
Explanationzln test case 1:4 integers are 4,2,5,1. So maximum sum is 12. In test
case 2: 4 integers are 52,3,1,0. So maximum sum is
56. In test case 3: None of division (0 , O , 0 , 06) , (0 , 00 , 0 , 6 ) is valid.
SUBTASKS: subtask 1 1 1<= N<=102 : ( 50 pts ) subtask 2 :
1<=N<=104 : (50 pts)
Source Code
#include <stdio.h>
#lnclude<string.h>
char s[21]I
long lnt arr[21][4];
int main()
l
long int n;
//prlntf("Enter number of strings:\n");
scanf("%ld",&n);
while (n--)
{
/lprintf("The strings are:\n");
scant("/<>s\n",s);
long Int len.l.j,k,val=0,count=O,x:
len=strlen(s):
if (len<4)
{ printi("The output isiunluckyin");
continue;
}
for (l=0;i<len;i++)
(for (j=0;j<4;j++)
{arr[i][j]=-9999999:
l
l
for (l=0;klen-3;l++)
{ val=s[q-'0'+1O'val;
If (val==0)
{
count++;
l
It (count==2)
{
break;
l
arr[l][0]=val;
tot (l=1:i<len;i++)
l
x=0;
long int val=0;
count=i;
for (j=i:j<len-3+i;]++)
{
val=s[j]-'0'+10'val;
for (k=O;k<i && k<4IK++)
{
if (arr[i-1][k]+val>arr[count][k+11)
i
arr[count][k+1]=arr-1][k]+val;
l
l
It (val==0)
{
break;
}
count++;
l
l
if (arr[len-1][3]<O)
printf("The output iszunluckyin");
else
printt("The output ls:%ld\n'.arr[len-1][3]);
}
i
Sample Input
3
4251
5231 0
00006
Sample Output
The output is:12
The output is:56
The output iszunlucky
Result
Thus, Program " Class Homework " has been successfully executed

Course: C ?:.|b]6Cl Code


Q. DIAGONAL MATRIX
Diagonal Matrix.A square matrix which has zeros everywhere other than the main
diagonal Entnes on the main diagonal may be any
number, including 0 Write a program to find whether a given matrix IS a diagonal
matrix or not Input Format The input consists of
(n'n+1) integers The first integer corresponds to the number of rows/columns in the
matrix The remaining mtegers correspond to the
elements in the matnx The elements are read in rowwise order, first row first, then
second row and so on Assume that the maximum
value of m and n IS 5 Output Format Print yes if it IS a diagonal matnx Print no if
it IS not a diagonal matrix
Source Code
#Include<stdlo.h>
#include<stdlib.h>
int createArray(int)
void getElements(int" lnt)
void diagonalElements(|nt int)
int main()
t
lnt "a,n;
//printf("enter the numberof rows/columns\n )
scanf("%d".&n):
a=createArray(n):
getElements(a,n);
dlagonalElements(a n)
retum 0:
l
lnt "'createArray(int n)
(
lt i,a;
a=(Int")ma|loc(n'sizeof(|nt'))
for(l=01i<n;l++)
l
'(a+|)=malloc(n'sizeof(lnt))
l
retum a:
l
void getElements(int "a Int n)
(
rm l,j;
/iprintt("enter the elements of the matr|x\n )
for(l=0:i<n:l++)
l
for(j=0;]<n;j++)
i
scanf("%d'.(a+i)+j)
l
l
~
l
void diagonalElements(|nt "a Int n)
(
lnt l,j,c=0;
for(l=0;i<n;l++)
(
for(j=0;j<n;j++)
l
if(ll=j)
(
"(('('(a+i)+l))==)
l
c++;
l
l
l
l
lf(c==((nn)-n))
(
printf("yes\n"):
l
else
i
printf("no\n")1
l
)
Sample Input
2
4 5
5 4
Sample Output
H0
Result
Thus, Program " DIAGONAL MATRIX " has been successfully executed

course: C mject Code:


Q. UNIFORMITY MATRIX
Uniformity matrix is a matrix in which all the elements in the matrix are either
completely even or completely odd. Write a C program to
nd whether a given matrix is a uniformity matrix or not. Input Format: The input
consists of (n*n+1) integers. The first integer
corresponds to the number of rows/columns in the matrix. The remaining integers
correspond to the elements in the matrix. The
elements are read in rowwise order, first row first, then second row and so on.
Assume that the maximum value of m and n is 5. Output
Format: Print yes if it is a uniformity matrix. Print no if it is not a uniformity
matrix.
Source Code
#lnclude<stdlo.h>
#include<stdlib.h>
lnt "createArray(int):
void getElements(int",int);
void unitormityD|agonals(int",int):
lnt main()
(
Int "a,n:
//printt("enter the size of the matrix\n");
scanf("%d".&n):
a=createArray(n):
getElements(a,n);
uniformityDiagonaIs(a,n);
retum 0:
l
Int "createArray(int n)
f
lnt"a,I1
a=(Iht")malloc(nsizeof(int))1
for(l=0:i<n;i++)
l
'(a+l)=(int)mall0c(n'sizeof(int));
l
retum a:
l
void getE|ements(int a,|nt n)
f
lnt l,j;
//printf("enter the elements of the martrix\n');
for(l=0:i<n:l++)
i
for(j=0;]<n;j++)
l
scanf("%d.('(a+I)+]));
l
l
l
void uniformityDiagona|s(int a.int n)
(
Int l,j,b=0.c=0,d,e;
for(l=0;i<n;l++)
l

for(j=0;j<n;j++)
(
"(i==i)
(
d=(('(a+t)+l));
if((d=e)&&(dl=0))
i
printf("no\n");
retum;
l
l
l
e=d:
l
for(i=0;i<n;l++)
(
for(j=0;j<n;j++)
l
1r<t('<'a+i)+1>>%2==<>>)
f
C++;
l
else
t
b++;
l
l
l
"(==("')l|b==("'"))
l
printf("yesn");
l
else
t
printf["no\n");
l
l
Sample Input
2
45
54
Sample Output
HO
Result
Thus, Program " UNIFORMITY MATRIX" has been successfully executed

Course: C Spbject Code:


Q. SYMMETRIC MATRIX
A symmetric matrix is a square matrix that is equal to its transpose. Write a C
program to find whether a given matrix is a square matrix
or not. input Format: The input consists of (m'n+2) integers. The first integer
corresponds to m, the number of rows in the matrix and the
second integer corresponds to n, the number of columns in the matrix. The remaining
integers correspond to the elements in the matrix.
The elements are read in rowwise order, first row first, then second row and so on.
Assume that the maximum value of m and n is 10.
Source Code
#include<stdl0.h>
#lnclude<stdl|b.h>
lnt "createArray(int,int);
void getEiements(int",int.int);
void symmetrlcMatrix(int",int,int)I
lnt maln()
l
int "a,rows,columns;
//printf("enter the number of rows and columns\n");
scanf("%d'.&rows);
scanf("%d".&columns);
a=createArray(rows.columns):
getElements(a,rows,columns)I
symmetricMatrh(a,rows,columns);
retum 0;
l
int "createArray(int rows,int columns)
l
lnt i,"a;
a=(int")malioc(rows'sizeof(int'))Z
for(i=0:krows;i++)
l
'(a+l)=(int')malloc(columns'(sizeof(int)));
l
retum a;
l
void getElements(int "a.int rows,int columns)
(
Int l,j;
I/printf("enter the elements of the matrix\n");
tor(i=0;i<rows;i++)
l
for(j=0;j<columns;]++)
(
scanf("%d".('(a+i)+j)):
l
l
l
void symmetrlcMatrix(int "a,int rows,int columns)
l
lnt i,j,c=O;
tor(l=03i<rows;l++)
l
for(j=0;]<coiumns;j++)
l
inr"<'<a+i>+m==<'<'<a+n+i>
l
C++;
l
l
l
if(c==(rowscolumns))
l
prlntf("Symmetric\n):
l
else
l
printf("Not Symmetrictn);
l
l
Sample Input
2
2
1 1
2 2
Sample Output
Not Symmetric
Result
Thus, Program " SYMMETRIC MATRIX " has been successfully executed

Course: C Srbject Code:


Q. LOWER TRIANGULAR MATRIX
A lower triangular matrix is a square matrix in which all the elements above the
diagonal are zero. That is, all the non-zero elements are
in the lower triangle: Write a C program to find whether a given matrix is a lower
triangular matrix or not. Input Format: The input consists
of (n"n+1) integers. The rst integer corresponds to the number of rows/columns in
the matrix. The remaining integers correspond to the
elements in the matrix. The elements are read in rowwise order, first row first,
then second row and so on. Assume that the maximum
value of m and n is 5. Output Format: Print yes if it is a lower triangular
matrix . Print no if it is not a lower triangular matrix.
Source Code
#include<stdlo.h>
#include<stdlib.h>
int "createArray(int);
void getElements(int",lnt);
void trlangularMatrix(int",int);
int main()
l
lnt "a,n;
I/printf("enter no.of rows!columns\n");
scanf("%d".&n):
a=createArray(n):
getElements(a,n);
triangularMatrh(a__n);
retum O:
l
lnt "'createArray(int n)
(
lnt a,i;
a=(Int")malloc(n'sizeof(int))I
for(i=0:i<n;l++)
l
(a+l)=(lnt')malloc(n'sizeof(int));
l
retum a:
l
void getElements(int"a,int n)
l
int L];
/iprintt("enter the elements of the matrix\n");
for(l=0:i<n:l++)
l
fOl(j=OZ]<n;j++)
l
scanf("%d'.(a+i)+j);
l
l
l
void triangularMatrix(lnt"a.int n)
l
lnt l,j;
for(j=0;j<n;]++)
l
for(i=0;i<n:l++)
l
lf(l'('(a+i)+l))==&8-(l>|i)
l
l
else lf(((*((a+|)+j))!=0)&&[j>i))
l
prlntf("No");
retum;
}
l
l
printf("Yes"); }
Sample Input
2
1 2
s 3
Sample Output
No
Result
Thus, Program " LOWER THIANGULAR MATRIX" has been successfully executed

course: C Srbject Code:


Q. Art
Chefs new hobby is painting, but he learned the fact that its not easy to paint 2D
pictures in a hard way, after wasting a lot of canvas
paper, paint and of course time. From now on, he decided to paint 1D pictures only.
Chefs canvas is N millimeters long and is initially all
white. For simplicity, colors will be represented by an integer between 0 and 105.
0 indicates white. The picture he is envisioning is also
N millimeters long and the ith millimeter consists purely of the color Ci.
Unfortunately, his brush isnt fine enough to paint every millimeter
one by one. The brush is 3 millimeters wide and so it can only paint three
millimeters at a timewith the same color. Painting over the
same place completely replaces the color by the new one. Also, Chef has lots of
bottles of paints of each color, so he will never run out
of paint of any color. Chef also doesnt want to ruin the edges of the canvas, so he
doesnt want to paint any part beyond the painting.
This means, for example, Chef cannot paint just the first millimeter of the canvas,
or just the last two millimeters, etc. Help Chef by telling
him whether he can finish the painting or not with these restrictions. Input The
first line of the input contains an integer T denoting the
number of test cases. The description of T test cases follows. The first line of
each test case contains a single integer N. The second line
contains N space-separated integers C1, C2, ..., CN
Source Code
#lnclude<stdlo.h>
#dene g getchar_unlocked
int read()
{
int n=0;
char c=g();
while(c<'0' || c>'9')
=9();
whlle(c>='0' && c<='9)
{
n = (n<<3) +(n<<1) +6 - '0';
=9():
l
return n;
1
int main()
{
lnt t,i,n,ag1=O,flag2=0,temp.temp1 ;
t=read();
whlle(t--)
{
n=read();
tempt =0;
for(i=0;|<n:++i){
temp=read();
lf(temp1==temp)
flag2++;
else if(temp1!=temp)
{temp1=temp;
flag2=0;}
lf(ag2 %2==0 && flag2>0)
l
flagl =1 ;
l
l
1 ==1 )
pri ntf("Yes\n");
else
prlntf("No\n")I
tempt =0;
flag 1 =0;
8Q2=0
l
return 0;
l
Sample Input
3
4
1555
4
1115
3
552
Sample Output
Yes
Yes
No
Result
Thus, Program " Art" has been successfully executed

course: C Spbject Code:


Q. Sherlock Homes
There is a mysterious temple in Mysteryland. The door of the temple is always
closed.lt can only be opened by a unique
procedure.There are two boxes and N items outside the temple.Sherlock homes visits
the temple many times.Each time Sherlock
holmes visits the temple,the number of items N outside the door of the temple is
changed but each time he anyhow manages to know
the cost of those N items.The door of the temple can only be opened if those "N
items" are distributed in those two boxes such that the
sum of cost of items in one box is equal to the sum of cost of items in other
box.Sherlock homes is trying to do such a distribution so as
to open the door of the temple.you have to tell whether the door the temple can be
opened or not. INPUT the first line contain the
number of test cases i.e the number of time sherlock homes visits the temple. Next
lines contains the description of those test cases.For
the first line contain number of items "N".The second line contains cost of those N
items. OUTPUT output "YES" if the door of the temple
can be opened otherwise output "NO". Constraint: 1 <= testcases <= 10 1 <= N <= 100
1 <= cost <= 100 Explanation there are three
testcases testcase 1:the items can be distributed in the boxes as 4 3 3 4,3,3 , 5 5
5,5 so output is YES testcase 2: the items can be
distributed in the boxes as 4 1 4,1 3 2 3,2 so output is YES testcase 3: such a
distribution is not possible.
Source Code
#include <stdio.h>
int DoorTest(lnt ltems[], int n. int sum)
l
if Base Cases
li (sum == O)
return 1;
(n == 0 Sum !=
retum 0;
if (ltems[n-1] > sum)
retum DoorTest(items, n-1, sum);
return (DoorTest(items. n-1. sum-items[n-1]) || DoorTest(items, n-1, sum));
l
lnt maln()
l
lnt noc.test:
//printf("Enter the number of test cases: \n'):
scanf("%d",&test);
for(noc=0;noc<test;noc++)
l
lnt items[100],totalsum=0;
int n,I;
//prlntf("Enter the number of items: \n");
scant("%d'.&n);
//printi(" Enter weight of items: in");
for(i=0:kn;l++)
( scanf("%d"__&items[i]);
totalsum+=items[i]2
l
it (totalsum/<>2==1)
prlntf("NO\n");
else if (DoorTest(items. n. totalsum/2) == 1)
prlntf("YES\n");
else
prlntf("NO\n")_:
}
retum 0;
l
Sample Input
3
5
43553
4
1234
2
12
Sample Output
YES
YES
NO
Result
Thus, Program " Sherlock Homes" has been successfully executed
Course: C Srbject Code:
Q. Temperature
The daily maximum temperature recorded in 10 cities during the month of January
(for all 31 days) have been tabulated as follows: City
1 2 3 4 5 6 '??'?????????10 Day 1 2 3 . . . . 31 Write a program to read the table
elements into a two-dimensional array temperature, and
to find the city and day corresponding to a) the highest temperature b) the lowest
temperature
Source Code
#include<stdio.h>
int maln()
l
int cityday[5][5];
int i,j,max.min,m.n:
m=n=1 I
prlntt("\n");
tor(i=0;k5;i++)
l
for(j=0;j<5;j++)
scanf("%d'.&cityday[i][j]);
}
max=cltyday[0][0]I
for(l=0;i<5:i++)
l
for(]=0;]<5;j++)
{
if(max<cityday[|][]])
{
max=cltyday[i]l]]; m=]+1; n=l+1;
l
}
l
printf("Max temperature %d in city no %d on the day %d".max_.m,n):
min=cltyday[0][0];
m=rl=1 I
for(i=0;i<5;i++)
l
for(j=0;j<S;j++)
l
lf(min>cityday[l][|])
{
min=cityday[l][j];
m=j+1; n=i+1;
l
l
}
prlntf("\nMin temperature %d in city no %d on the day %d",min,m,n);
retum O;
1
Sample Input
so 121 -1 as
31 10 2 -2 as
33132-234
34123-236
3715 5-137
Sample Output
Max temperature 37 in city no 1 on the day 5
Min temperature -2 in city no 4 on the day 2
Result
Thus, Program " Temperature" has been successfully executed

Subject Code:
Course: C H
Q. Ballots
An election is contested by 5 candidates. The candidates are numbered 1 to 5 and
the voting is done by marking the candidate number
on the ballot paper. Write a program to read the ballots and count the votes cast
for each candidate using an array variable count. In
case a number read is outside the range 1 to 5 ballot should be considered as a
spoilt ballot and the program should also count the
number of spoilt ballots.
Source Code
#lnclude<stdlo.h>
int maln()
l
Int i.].k.I.m,n,count=0,voter[6]={0};
]=1:k=2:l=3:m=4;n=5;
printf("press 1 to 5 for voting:\n");
printt("press 0 for stop votlng:");
scanf("%d',&i);
while(ll=0)
l
lf(l==1)
l
voter[1 ]++;
l=I;
}
else lf(i==2)
l
voter[2]++;
k=|;
l
else ll(i==3)
l
voter[3]++;
l=|;
l
else if(i==4)
{
voter[4]++;
m=l;
}
else lt(i==5)
l
voter[5]++;
n=|;
1
else lf(i>5)
{
count++;
}
else
l
voter[0]++2
i
l
scant("/<>d",&i);
l
printt("\nCandidate %d has votes=%d".j, voter[i]);
printt("\nCandidate /od has votes=%d'.k, voter[k]);
pnntf("\nCandidate %d has votes=%d',l, voter[l]);
printf("\nCandldate /od has votes=%d'.m, voter[m]):
printf("\nCandidate %d has votes=%d".n, voter[n]);
printf("\n/<>d no.0! spoilt votes",count);
retum O;
l
Sample Input
ON-#0301-I>CdN*
Sample Output
press 1 to 5 tor voting:
press 0 for stop votlng:
Candidate 1 has votes=3
Candidate 2 has votes=2
Candidate 3 has votes=1
Candidate 4 has votes=1
Candidate 5 has votes=1
1 n0.of spollt votes
Result
Thus, Program " Ballots " has been successfully executed

course: C Stibject Code:


Q. Selection Sorting
Selection sort is based on the following idea: Selecting the largest array element
and swapping it with the last array element leaves an
unsorted list whose size is 1 less than the size of the original list. If we repeat
this step again on the unsorted list we will have an
ordered list of size 2 and an unordered list size n-2. When repeat this until the
size of the unsorted list becomes one , the result will be a
sorted list. Write a program to implement this algorithm.
Source Code
#lnclude<stdlo.h>
lnt maln()
l
Int A[1O];
int l,k.Small.Loc;
//printt("Enter Elements of Array:---\n");
for(l=0;i<=9;i++)
scanf("%d".&A]);
for(k=O;k<=9;k++)
l
Small=A[k];
LOC=k:
for(i=k;k=9;i++)
lf(Small>A[l])
(
Small=A[i];
LOC=i;
l
A[Loc]=A[k]:
A[k]=Small;
l
//printt("Sorted Array is:\n\n");
for(i=0;i<=9;i++)
I/printt("%d ",A]);
A[k]=Small;
//printf("Sorted Array is:\n");
for(l=0;i<=9;i++)
printf("%d ",A[i]);
retum 0;
)
Sample Input
10
11
13
10
12
11
19
17
20
22
Sample Output
1o1o1111121s171s2o22
Result
Thus, Program " Selection Sorting" has been successfully executed

Course: C Srbject Code:


Q. Binary Search
Develop a program to implement the binary search algorithm. This technique compares
the search key value of the element that is
midway in a soned lies. Then ; (a) If they match, the search is over. (b) It the
search key value is less than the middle value, then the
rst half of list contains the key value. (c) If the search key value is greater
than the middle value, then the second half contains the key
value. Repeat this divide and~conquer strategy until we have match. lf the list is
reduced to one non-matching element, then the list does
not contain the key value.
Source Code
#lnclude<stdlo.h>
lnt maln()(
lnt l,beg,end,mld,a[20],ltem;
//printf("Enter 13 elements\n"):
f0I(i=1Ii<=13Zi++)
l
scanf("%d",&a]);
l
//printt("\nEnter what item you want to search\n");
scanf("%d".&item);
b@9=1I
end=13;
mid=((beg+end)/2);
whlle(beg<=end && a[mld]!=ltem)
i
it(item<a[mld])
l
end=mld-1 :
}
else
{
beg=mid+1;
l
mld=((beg+end)/2);
l
lt(item==a[mld])
printf("The Item ls in the llst and its position ls=%d'.mid);
else
print1("The item ls not in the list"):
return 0:
l
Sample Input
10111213132478110122123
2
Sample Output
The item ls ln the list and its position ls=7
Result
Thus, Program " Binary Search " has been successfully executed

Course: C Spbject Code:


Q. No of Distinct elements in a Unsorted array
Write a program to find the number of distinct elements in a unsorted array. [Do it
without sorting the array] Input Format: Input consists
of n+1 integers. The first integer corresponds to n, the number of elements in the
array. The next n integers correspond to the elements
in the array. Assume that the maximum value of n is 15. Output Format: Output
consists of a single integer which corresponds to the
number of distinct elements in the array.
Source Code
#lnclude<stdio.h>
#incIude<stdlIb.h>
int createArray(int);
void readElement(int ',int);
void distinctElement(int ,int):
int main()
t
int 'a,n;
scanf("/<>d".&n):
a=createArray(n)I
readElement(a.n);
distlnctEIement(a.n);
retum 0;
I
Int 'createArray(int n)
t
int a;
a=(int )malIoc(n'size0t(int));
retum a:
I
void readElement(int 'a,int n)
(
Int I:
for(i=0:i<n:I++)
I
scanf("%d".a+i):
I
I
void distinctE|ement(int a.int n)
I
Int l,j,b=1,d=0;
tor(i=0;i<n:|++)
t
d++;
for(j=i+1;]<n;j++)
I
If('(a+i)=='(a+j)&&b==1)
l
d--;
b=0;
I
I
b=1 :
I
printt("/>d',d);
I
Sample Input
5
32378090
Sample Output
4
Result
Thus, Program " No of Distinct elements in a Unsorted array" has been successfully
executed

course: C Srbject Code:


Q. Sum of positive Numbers
Write a program to find the sum of positive numbers in an array. Input Format:
Input consists of n+1 integers. The first integer
corresponds to ?n? , the size of the array. The next ?n? integers correspond to the
elements in the array. Assume that the maximum
value of n is 15. Output Format: Refer sample output for details.
Source Code
#lnclude<stdlo.h>
#lnclude<stdllb.h>
Int 'createArray(int):
void readElement(lnt ',int);
int sumofArray(lnt '.lnt);
int maln()
l
lnt a,b.nI
scanf("%d'.&n)l
a=createArray(n);
readElement(a,n);
b=sumofArray(a,n);
printf("The sum of the positive numbers in the array ls:/>d",b);
retum 0;
l
int createArray(int n)
l
lnt a;
a=(int ')malloc(n'sizeof(lnt));
retum a;
l
void readE|ement(lnt 'a,int n)
t
lnt i:
for(l=0;i<n;i++)
l
scanf("%d",a+i);
l
i
int sumofArray(int 'a.|nt n)
(
lnt i,sum=0;
for(l=0;i<n;i++)
(
lf('(a+i)>0)
(
sum=sum+(a+i);
i
l
//printf("%d.sum);
retum sum;
)
Sample Input
5
2368-1
Sample Output
The sum of the positive numbers in the array is:19
Result
Thus, Program " Sum of positive Numbers" has been successfully executed

Q. Alphabetical Order
Write a progra
GINRST.
Source Code
#include<stdIo.h>
#lnclude<strIng.h>
lnt maln()
(
char a[30],temp2
Int n=0,j,i;
printf("\nEnter the
scanf("%s",a);
while(a[n]l='\O)
(
n++;
l
for(i=0;i<n;l++)
l
for(j=0:j<n-i-1;j++)
(
"(1=1[i1>==\[i+1])
i
temp=a[;
a[]]=a[j+1]I
a[|+1]=temp;
l
l
l
printf("\nThe string
for(i=0:i<n;I++)
l
printf("%c',a[i]);
l
retum 0:
l
Sample Input
string
Sample Outpu
Enter the string:
The string ln alph
abet
Result
Thus, Program
course: C fpbject Code:
m
which will read a string and rewrite it in the alphabetical order. For example, the
word STRING should be written as
strlng:")l
in alphabetical order is:");
t
ical order is:glnrst
" Alphabetical Order" has been successfully executed

course: C ?:.lb]eC\ Code:


Q. ASCII Name
Write a program which reads your name from the keyboard and output a list of ANCII
codes, which represent your name
Source Code
#include<stdio.h>
#lnclude<string.h>
int main()
t
int k,i,|:
char x[100];
printf("Enter a STFtlNG:\n'):
scanf("%s",x);
l=str|en(x);
printf("The ASCII values of the string are:\n");
for(i=0;i<|;i++)
{
k=x[i];
printt("%d ",k);
l
retum O;
}
Sample Input
SRMUNIVERSITY
Sample Output
Enter a STRING:
The ASCII values of the strlng are:
83 82 77 85 78 73 86 69 82 83 73 84 89
Result
Thus, Program " ASCII Name " has been successfully executed
Course: C Srbject Code:
Q. Character Extract
Write a program to extract a portion of a character string and print the extracted
string. Assume that m characters are extracted, starting
with the nth character.
Source Code
#include<stdlo.h>
#dene MAX 50
int ma|n()
t
char Str1[MAX]:
int i,m.n.];
printf(Enter A Stringz");
scanf("%s",Str1 );
printt("\nEnter Number of Characters Which You Want to Extract");
scant("%d".&m):
printt("\nEnter Beginning Index from which You Want to Extractt");
scanf("%d",&n);
printf("\nExtracted String is:");
tor(i=n-1;i<m+n-1;i++)
l
pftI'ltf("/oC'.$U1[i])
l
retum O;
l
Sample Input
SRMUniversityLearnlngCentre
10
5
Sample Output
Enter A String:
Enter Number of Characters Which You Want to Extract:
Enter Beginning Index from Which You Want to Extract:
Extracted String is:niversityL
Result
Thus, Program "Character Extract " has been successfully executed

course: C Srbject Code:


Q. Consecutive String Copy
Write a program that will copy m consecutive characters from a string s1 beginning
at position n into another string s2
Source Code
#incIude<stdio.h>
#define MAX 50
int main()
l
char Str1[MAX],Str2[MAX];
int i,m,n,j;
printf("\nEnter A Strlngz");
soant("%s",Str1 );
printf("\nEnter Number of Characters Which You Want to Copyi"):
scant("%d".&m):
printt("\nEnter Beginning Index from Which You Want to Copy:"):
scant("%d',&n);
tor(l=n-1,j=0;i<m+n;l++_j++)
(
Str2[j]=Str1];
l
Str2[m]='\0;
printt("\nCopied String iSI/o$".Stt2);
return 0;
l
Sample Input
SRMUnIverslty
5
1
Sample Output
Enter A String:
Enter Number of Characters Which You Want to Copy:
Enter Beginning Index from Which You Want to Copy:
Copied String is:SRMUn
Result
Thus, Program " Consecutive String Copy " has been successfully executed

course: C Srbject Code:


Q. Conversion Code -01
Write a C program to convert lowercase string to uppercase string using inbuilt
string library function strupr()internally characters in C
are represented as an integer value known as ASCII value. Which means if we write A
or any other character it is translated into a
numeric value in our case it is 65 as ASCII value of A = 97. Here what we need to
do is first we need to check whether the given
character is lowercase alphabet or not. It it is lowercase alphabet just subtract
32 from it which will result in uppercase alphabet (Since
ASCII value of A=65, a=97 their dierence is 97-65 = 32).
Source Code
#include<stdlo.h>
#detlne MAX_SIZE 100 //Maxlmum size of the string
lnt maln()
l
char strlng[MAX_SlZE];
int i;
I Reads a string from user '/
printf("\nEnter your texti");
scanf("%s",strlng);
tor(i=0; strlng[l]l=\0'; i++)
l
/.
' If current character is lowercase alphabet then
' convert lt to uppercase.
'1
if(string[i]>='a' && string[i]<=z)
(
string[i] = string[i]-32;
l
l
printt("\nUppercase string:/<>s",string);
return 0;
l
Sample Input
srmunlversity
Sample Output
Enter your text:
Uppercase strlng:SFtMUNlVEFtSlTY
Result
Thus, Program " Conversion Code -O1 " has been successfully executed

Course: C Srbject Code:


Q. Conversion Code -02
Write a C program to convert uppercase string to lowercase using inbuilt string
library function strlwr(). How to use strlwr library function
in C programming. Internally characters in C are represented as an integer value
known as ASCII value. Which means if we write a or
any other character it is translated into a numeric value in our case it is 97 as
ASCII value of a = 97. Here what we need to do is first we
need to check whether the given character is upper case alphabet or not. If it is
uppercase alphabet just add 32 to it which will result in
lowercase alphabet (Since ASCII value of A=65, a=97 their difference is 97-65 =
32).
Source Code
#lnclude <stdio.h>
#deflne MAX_SlZE 100 //Maximum size of the string
Int ma|n()
I
char string[MAX_SlZE];
Int i;
/ Reads string from user '/
printf("\n Enter any stringz");
scanf(%s" ,strl ng);
//Runs a loop tlll last character of string
t0r(i=0; strlng[l]l='\0; I++)
I
if(strlng[l]>='A' && strlng[l]<='Z')
I
string[i] = string[i] + 32;
I
1
printf(\nLower case string:%s", string);
return 0;
I
Sample Input
SRMUNIVERSITYLEARNINGCENTRE
Sample Output
Enter any string:
Lower case string:srmunIversitylearningcentre
Result
Thus, Program "Conversion Code -02 " has been successfully executed

course: C Srbject Code:


Q. Copy Count
Write a C program to copy one string to another string using loop. C program to
copy one string to another without using inbuilt library
function strcpy() and count total number of characters copied. How to copy one
string to another and count total characters copied with
and without using inbuilt string library function
Source Code
#include <stdio.h>
int maln()
(
char text1[100]. text2[100];
int i;
printt("Enter any string: ");
scanf("%s",text1 )3
/' Copies textt to text2 character by character '/
=0;
wh||e(text1[l]l='\0)
{
text2[i] = textl [i];
i++;
}
//Makes sure that the string is NULL terminated
text2[i] = '\0';
printf("\nFlrst strlng=%s",text1)I
printt("\nSecond string=%s",text2):
printt("\nTotal characters copied=%d", I);
return 0;
i
Sample Input
SRMUniversity
Sample Output
Enter any string:
I"-_llS1 str|ng=SFtMUnivers|ty
Second string=SRMUnlversity
Total characters copied=13
Result
Thus, Program " Copy Count " has been successfully executed

Course: C Srbject Code:


Q. Count a String
Write a C program to count total n
Source Code
#include <stdio.h>
umber of alphabets, digits or special characters in a string using loop How to find
total number of
alphabets, digits and special characters in a string in C programming
#detlne MAX_SlZE 100 //Maxlmum size of the string
lnt main()
l
char string[MAX_SlZE];
int alphabets. digits. others, I;
alphabets = digits = others = i = 0;
I Reads a strlng from user '/
printf("Enter any string:");
scanf("%s,string):
[Q
' Checks each character of string
'/
whlle(strlng[i]l=\0')
{
if((strlng[l]>='a' && strlng[l]<='z')
{
alphabets++;
}
else lf(string[i]>=0' && strlng[l]<=9')
l
digits++;
l
else
{
others++;
}
i++Z
l
printt(\nAlphabets=%d", alphabets);
printf("\nDlgits=%d", digits);
printf("\nSpecial characters=%d", others
return 0:
l
Sample Input
SRM!Universlty@Leaming&Centre@1 1 13
Sample Output
Enter any string:
Alphabets=27
Dlglts=4
Special characters=4
Result
Thus, Program " Count a String "
|| (strlng[l]>='A' && strlng[i]<='Z'))
l;
has been successfully executed

course: C Srbject Code:


Q. Frequency of each
Write a C program to count frequency of each character in a string using loop
Source Code
#Inc|ude <stdio.h>
#Include <string.h>
#def|ne MAX_SlZE 100 //Maximum size of the string
Int main()
I
char string[MAX_S|ZE];
Int i, Ien;
Int frequency[26];
/' Reads a string from user I
printf("Enter any string: ");
scanf("%s",strlng);
len = stilen(strlng);
/ Initializes frequency of each character to 0 '/
tor(i=0: i<26: i++)
I
frequency[q = 03
}
/* Finds total number of occurrences of each character '/
f0I'(i=0; i<len; i++)
I
/' If the current character is lowercase alphabet '/
it(strlng[l]>='a' && string[i]<='z)
t
frequency[string[i] - 97]++;
I
else If(string[l]>='A && string[q<=Z')
I
frequency[strlng[l] - 65]++;
I
}
/Q
Prints the frequency of all characters In the string
I
printf("\nFrequency of all characters in the given string: \n"):
for(i=0; i<26; i++)
I
I If the current character is In given string I
if(frequency[i]l=0)
t
printf("%c = %d\n". (i+97), frequency[i]);
I
I
return 0:
I
Sample Input
smmnlversitylearntngcentre
Sample Output
Enter any string:
Frequency of all characters In the given string:
a = 1
= 1
<<C"M":3_'_"(QDO
_._._.|\7|\>-l>;;_ _.,;;
=3
=1
Result
Thus, Program " Frequency of each " has been successfully executed

course: C Spbject Code:


Q. Maximum Frequency
How to find highest frequency character in a string using loop in C
programming.Find frequency of each characters in the string and
store it in some array of integers. Find maximum element in the array. Maximum
element in the array will the be maximum occurring
character in the string.
Source Code
#lnclude <stdio.h>
#deflne MAX_SlZE 100 //Maximum size of the string
#define MAX_CHARS 255 //Maximum characters allowed
lnt maln()
t
char string[MAX_SlZE];
int frequency[MAX_CHARS]: //Stores frequency of each character
int i = 0, max;
int ascii;
printf("Enter any string: ");
scanf('%s",strlng);
/ Initializes frequency of all characters to 0 I
for(i=0I i<MAX_CHARS; i++)
{
frequency[|] = 0:
)
/' Finds frequency of each characters '/
i=0;
whlle(string[i] l= '\0')
{
ascli = (int)strIng[l];
frequency[ascii] += 1;
i++2
}
/ Finds maximum frequency '/
max = O2
f0|'(i=0; i<MAX_CHARSl |++)
{
if(frequency[i] > frequency[max])
max = i;
}
printf("\nHighest frequency of /0C is /Od \n", max, frequency[max]);
return 0:
l
Sample Input
srmunlversity
Sample Output
Enter any string:
Highest frequency of i is 2
Result
Thus, Program "Maximum Frequency " has been successfully executed

Course: C Sybject Code:


Q. Minimum Frequency
How to find lowest frequency character in a string using loop in C programming
Source Code
#include <stdio.n>
#define MAX_SlZE 100 //Maximum size of the string
ffdeflne MAX__CHARS 255 //Maximum characters allowed
int maln()
l
char string[MAX_SlZE];
int frequency[MAX_CHARS]; /1Stores frequency of each character
lnt i = O, min:
Int ascii;
printf("\nEnter any string:");
scanf("%s".string);
/' Initializes frequency of all characters to 0 'r
for(i=0; i<MAX__CHARS: l++)
{
frequency[|] = 0:
}
/' Finds frequency of each characters '/
i=0;
whlle(string[i] != '\0')
{
ascli = (int)string[l]:
frequency[asciq += 1;
i++;
l
/' Finds minimum frequency I
mln = 0;
for(i=0; i<MAX_CHARS; I++)
{
if(frequency[l] l= O)
i
if(frequency[min] == 0 || frequency[i] < frequency[min])
min = I;
l
i
printf("\nLowest frequency of /0C is %d", min, frequency[min]);
return 0;
i
Sample Input
madam
Sample Output
Enter any string:
Lowest frequency of d is 1
Result
Thus, Program " Minimum Frequency " has been successfully executed

Course: C Srbject Code:


Q. Remove All occurrence
C program to remove all occurrences of a character from the string
Source Code
#lnclude <stdio.h>
#lnclude <string.h>
#deflne MAX_SlZE 100 //Maximum size of the string
1" Function declaration '/
void removeA|l(char ', const char):
int maln()
t
char string[MAX_SlZE];
char toFtemove;
printt("\n Enter character to remove from string:');
toFtemove = getchar();
printf("\nEnter any string :");
scanf("/>s",string);
removeAll(strlng, t0Remove):
printt("\nStn'ng after removing %c:/>s,toRemove, stnng);
return 02
l
[V0
' Function to remove all occurrences of a character from the string.
'/
void removeAll(char string, const char toRemove)
(
Int l, j;
lnt len = strlen(string);
tor(i=0; i<len; i++)
{
/I
If the character to remove is found then shift all characters to one
place left and decrement the length of string by 1.
'/
if(string[l] == toRemove)
t
ior(j=l; ]<len-1; j++)
l
strlng[j] = stringlj-+1];
)
len--;
string[len] = '\0';
/1 It a character is removed then make sure I doesn't increments
I--;
l
1
l
Sample Input
8
madam
Sample Output
Enter character to remove from string:
Enter any string:
String after removing azmdm
Result
Thus, Program " Remove All occurrence" has been successfully executed

Course: C Srbject Code:


Q. Remove Index String 1
Write a function to remove first occurrence of a word from the string.
Source Code
#include <stdio.h>
#include <string.h>
ffdene MAX_SlZE 100
I" Function declaration I
void removeFirst(char text, const char ' toRemove);
int main()
l
char text[MAX_SiZE];
char toRemove[MAX__SIZE]:
/Q
' Reads a string from user and character to be searched
I
printt("Enter any string:")I
scanf("%s,text);
printf("\nEnter string to be removedz");
scanf('%s",toRemove);
removeFirst(text. toRemove);
printf("\nFinai string after removing %s = /03'. toRemove. text);
return 0;
t
[I10
' Removes the first occurrence of a string in another string
I
void removeFirst(char text. const char ' toRemove)
i
int i, j;
int len, removeLen;
int found = 0;
Ien = strien(text);
removeLen = strlen(toRemove):
for(i=O; i<ien; i++)
{
found = 1;
for(j=0: i<removeLen; j++)
{
if(text[i+j] l= toRemove[j])
i
found = 0;
break;
i
i
/.
' if word has been found then remove it by shitting characters right to it to left.
'/
it(found == 1)
i
for(]=i; j<len-removeLen; j++)
i
text] = text + removeLen];
i
text[j] = '\0':
break;
}
}
i
Sample Input
SRMUNIVERSITY
SRM
Sample Output
Enter any string:
Enter string to be removed:
Hnal string after removing SRM = UNIVERSITY
Result
Thus, Program " Remove Index String 1 " has been successfully executed

Course: C Spbject Code:


Q. Remove Index String 2
Write a C program to remove from last occurrence of a word in given string using
loop
Source Code
#lnclude <stdio.h>
#lncIude <string.h>
#define MAX_SlZE 100 //Maximum size of string
int maln()
i
char string[MAX_SlZE];
char word[MAX_SIZE];
lnt i, 1, found. index;
lnt strlngLen. wordLen;
It
" Reads string and word from user
*1
printf("Enter any string:');
scanf("/>s".string)I
printf("mEnter any word to searchf):
scanf('/>s".word);
stringLen = strlen(string); //Finds length of string
w0rdLen = strlen(word); //Finds length of word
/t
' Runs a loop from starllng index of string to
length of string - word length
I
index = -1;
for(l=0; i<stringLen - wordLen; l++)
{
//Matches the word at current position
found = 1;
for(]=0; j<wordLen: j++)
{
//If word ls not matched
it(string[l+j] l= word[)
{
found = 0;
break;
l
l
//If word have been found then store the current found lndex
if(found == 1)
t
ll'ldeX =
l
l
//if WOl'd I101 found
lf(lndex == -1)
{
prlntf("\n%s not found",string);
}
else
{
['0
Shifts all characters from right to left
*1
for(l=index; i<stringLen - w0rdLen; l++)
{
string[i] = strlng[i + wordLen];
}
//Makes last character null.
string[i] = '\0':
prlntf("\nStrlng after removing last %s:%s", word, string);
l
return 0:
l
Sample Input
lLoveCProgramming
Love
Sample Output
Enter any string:
Enter any word to search:
String after removlng last Love:lCProgrammlng
Result
Thus, Program " Remove Index String 2 has been successfully executed

Course: C Srbject Code:


Q. Remove Index String 3
Write a C program to remove all occurrences of a given word in string using loop
Source Code
#lnclude <stdio.h>
#incIude <string.h>
#detine MAX_SlZE 100 //Maximum size of string
/' Function declaration '1
void removeAli(char " string, char ' toRemove);
lnt main()
l
char string[MAX_SlZE];
char toRemove[MAX_SIZE]:
/Q
' Reads string and word from user
I
printt("Enter any string: ");
scanf("%s",strlng);
printt("\nEnter word to remove: ");
scanf('%s",toRemove);
printi("\nString before removing %s :%s", toRemove, string);
removeAll(string, t0Remove):
printi("\nStn'ng after removing %s :%s", toRemove, string);
return 02
l
[IO
' Removes all occurrences of a given word in string.
'/
void removeAll(char string, char toRemove)
l
int l, j, stringLen, toRemoveLen;
int found;
stringLen = strlen(string): //Gets length of string
toRemoveLen = strien(toRemove); //Gets length of word to remove
for(i=0; i<stringLen - toFtemoveLen; i++)
l
/.
' Matches word with the string
'1
found = 1;
tor(j=0; j<toRemoveLen; j++)
l
if(string[i + j] l= toRemove[j])
l
tound = 0;
break;
1
l
It
If word is found then shift all characters to Iett
and decrement the string length
'/
if(found == 1)
i
f0r(j=i; i<stringLen - toRemoveLen; j++)
{
strlng[j] = string[j + toRemoveLen];
l
string] = '\O;
stringLen = stringLen - toRemoveLen;
}
i
l
Sample Input
SRMUNIVERSITYSRMUNIVEHSITY
SRM
Sample Output
Enter any string:
Enter word to remove:
String before removing SRM : SRMUNIVERSITYSRMUNIVERSITY
String after removing SRM : UNIVERSITYUNIVERSITY
Result
Thus, Program "Remove Index String 3 " has been successfully executed

Subject Code:
Course: C 11
Q. Remove Last occurrence
Write a C program to read any string from user and remove the last occurrence of a
given character from the string
Source Code
#include <stdio.h>
#lnclude <strtng.h>
#dellne MAX_SlZE 100 //Maximum size of the string
1" Function declaration '/
void removeLast(char . const char):
int main()
(
char string[MAX_SlZE];
char toRemove;
printf("Enter character to remove from stringz");
toRemove = getchar();
printt("\n Enter any string 1");
scanf('/>s",strlng);
removeLast(str|ng, toRemove);
printt("\nOutput:%s".string);
return 0:
l
PO
' Function to remove last occurrence of a character from the string.
'/
void removeLast(char ' string, const char toRemove)
(
Int I, |3SlPOS|tiOl'l
int len = strlen(string):
lastPosltion = -1;

whlle(i<len)
{
if(strlng[l] == toRemove)
l
lastPositlon = I;
}
i++;
I
if(lastPosition l= -1)
{
i = IastPosltion;
In
" Shift all characters right to the position tound above to left
'r
while(k|en-1)
l
string[i] = string[i+1];
i++;
}
l
/' Make the last character null /
strlng[i] = '\0';
l
Sample Input
3
madam
Sample Output
Enter character to remove from string:
Enter any string:
Output:madm
Result
Thus, Program " Remove Last occurrence " has been successfully executed

course: C Spbject Code:


Q. Remove Repeated Characters in a String
Write a C program to remove all repeated characters in a string using loops
Source Code
#include <stdio.h>
#detine MAX_SlZE 100 //Maximum size of the string
/' Function declarations I
void removeDuplicates(char ' string);
void removeAll(char " string, const char toRemove, int index);
int main()
l
char string[MAX_S|ZE];
/' Reads string from user '/
printt("\n Enter any string 1");
scanf(/>s".string):
printf("\nString before removing duplicates:%s", string):
removeDupllcates(string);
printf("\nString after removing duplicates:%s", string);
return 0;
l
',..
' Removes all duplicate characters from the given string
'/
void removeDuplicates(char ' string)
l
int l = O;
whl|e(string[i] != \0)
{
/ Remove all duplicate of character string[i] '/
removeAlI(string, strlng[l], i);
l++_Z
}
l
/..
' Removes all occurrences of a given character from string
' after the given Index.
'/
void removeA|l(char string, const char toRem0ve, int index)
l
Int l, j;
i = Index + 12
whlle(strlng[i] i= '\0')
{
/ It duplicate character is found "/
if(string[l] == toRemove)
l
f
' Shift all characters from current position to one place Ieit
..
l
while(string[|] l= '\0')
{
strlng[]] = string[j + 1];
j++;
}
}
l++;
}
l
Sample Input
smwuniversity
Sample Output
Enter any string:
String before removing dupllcateszsrmuniversity
String after removing duplicates:srmunivety
Result
Thus, Program " Remove Repeated Characters in a String" has been successfully
executed

Course: C Srbject Code:


Q. Remove Index String 1
Write a function to remove first occurrence of a word from the string.
Source Code
#include <stdio.h>
#include <string.h>
ffdene MAX_SlZE 100
I" Function declaration I
void removeFirst(char text, const char ' toRemove);
int main()
l
char text[MAX_SiZE];
char toRemove[MAX__SIZE]:
/Q
' Reads a string from user and character to be searched
I
printt("Enter any string:")I
scanf("%s,text);
printf("\nEnter string to be removedz");
scanf('%s",toRemove);
removeFirst(text. toRemove);
printf("\nFinai string after removing %s = /03'. toRemove. text);
return 0;
t
[I10
' Removes the first occurrence of a string in another string
I
void removeFirst(char text. const char ' toRemove)
i
int i, j;
int len, removeLen;
int found = 0;
Ien = strien(text);
removeLen = strlen(toRemove):
for(i=O; i<ien; i++)
{
found = 1;
for(j=0: i<removeLen; j++)
{
if(text[i+j] l= toRemove[j])
i
found = 0;
break;
i
i
/.
' if word has been found then remove it by shitting characters right to it to left.
'/
it(found == 1)
i
for(]=i; j<len-removeLen; j++)
i
text] = text + removeLen];
i
text[j] = '\0':
break;
}
}
i
Sample Input
SRMUNIVERSITY
SRM
Sample Output
Enter any string:
Enter string to be removed:
Hnal string after removing SRM = UNIVERSITY
Result
Thus, Program " Remove Index String 1 " has been successfully executed

Course: C Spbject Code:


Q. Remove String 1st Occurrence
Write a C program to read any string from user and remove first occurrence of a
given character from the string
Source Code
#lnclude <stdio.h>
#lnclude <string.h>
#deflne MAX_SlZE 100 //Maximum size of the string
/" Function declaration I
void removeFirst(char *, const char);
rm main()
l
char string[MAX_SlZE];
char toRemove;
printf("\nEnter character to remove from string: "):
toRemove = getchar():
printf("\nEnter any string: "):
scanf("%s",string);
removeFirst(string, toRemove):
printf("\nOutput:/<>s". string);
return 0;
i
,..
' Function to remove rst occurrence of a character from the string.
'/
void removeFlrst(char " string, const char toRemove)
t
lnt i;
int len = strlen(strlng);
=0;
/ Run loop until the rst occurrence of the character is not found /
whlie(klen && string]l=toRemove)
i++;
/I
' Shift all characters right to the posltlon found above to one place left
'1
whlle(klen-1)
{
strlng[i] = stnng+1]:
i++;
}
/* Make the last character null '1
string[i] = '\0':
)
Sample Input
l
srmunlversitylearningcentre
Sample Output
Enter character to remove from string:
Enter any string:
Output:srmunversltyleamingcentre
Result
Thus, Program " Remove String 1st Occurrence" has been successfully executed

Course: C Stibject Code:


Q. Replace 1st Occurrence of String
How to replace first occurrence of a character with another character in a string
using loop in C programming
Source Code
#include <stdio.h>
#define MAX_S|ZE 100 /rMaximum size of the string
/' Function declaration '/
void replaceF|rst(char ' string, char toReplace. char replacewith);
int main()
l
char string[MAX_SlZE], toReplace, replacewlth:
printf("Enter any stringz);
scanf(%s",string);
printf("Enter character to replace:");
scanf(' %c". &toReplace);
printf("Enter character to replace %c withz", toReplace);
scanf(' /00", &replaceWith);
printf("\nString before replacing:%s", string);
replaceFirst(strlng_. toReplace, replacewlth):
printf("\nStn'ng alter replacing?/us", string);
return 0;
l
PI
' Replaces the first occurrence of a character
' with another in given string.
'/
void replaceFirst(char string, char toReplace, char replacewlth)
l
int i=0:
/" Runs till the end of string /
while(string[i] l= '\0')
{
/ If an occurrence of character is found '1
if(string[l] == toReplace)
l
string[i] = replacevlth;
break:
l
i++;
i
l
Sample Input
arm
8
S
Sample Output
Enter any string:Enter character to replace:Enter character to replace a with:
String before replacingzarm
String after repiaclng:srm
Result
Thus, Program " Replace 1st Occurrence of String" has been successfully executed

Subject Code:
Course: C 11
Q. Replace a string
Write a C program to replace all occurrence of a character with another in a string
using function
Source Code
#include <stdio.h>
#define MAX_SlZE 100 //Maximum size of the string
/ Function declaration '/
void replace(char string. char toReplace. char replaceWith);
lnt main()
l
char string[MAX_SlZE], toReplace, replacewlth:
printf("Enter any string:");
scanf("%s",string)1
printf(Enter character to replace:"):
scant(' %c". &toReplace);
printf("Enter character to replace %c wlth:", toRep|ace):
scanf(" %c", &replaceWith);
printf("\nString before replacing:%s", string);
replace(string, toReplace, replacewlth);
printf("\nString after replacing: %s", string);
return 0:
l
PO
' Replaces the all occurrence of a character
' with another in given string.
I
void replace(char string, char toReplace, char replacewlth)
l
int i = O;
/ Runs tlll the end of string '/
whlle(string[i] l= we")
{
I If an occurrence of character is found "/
if(strlng[|] == toReplace)
i
string[i] = replaceVlth;
}
i++;
I
l
Sample Input
Sf3Sf3$Y8
8
m
Sample Output
Enter any string:Enter character to replace:Enter character to replace a with:
String before replaclngzsrasrasra
String after replacing: smlsrmsrm
Result
Thus, Program " Replace a string " has been successfully executed

course: C Subject Code:


Q. ASCII Name
Write a program which reads your name from the keyboard and output a list of ANCII
codes, which represent your name
Source Code
#incIude<stdio_h>
#lncIude<string.h>
Int main()
l
int k,i,l;
char x[100];
//printt("Enter a STRlNG:");
scanf("%s",x);
l=strlen(x);
printf("\nThe ASCII values oi the string arez-n");
tor(i=0;i<l;I++)
t
k=x[i];
pfII1("/od ",K);
I
retum 0;
}
Sample Input
SRMUNIVERSITY
Sample Output
The ASCII values of the string are:
83 82 77 85 78 73 86 69 82 83 73 84 89
Result
Thus, Program " ASCII Name " has been successfully executed
course: C Srbject Code:
Q. Inventor C
Write a program to do the following: (a) To output the question ?Who is the
inventor of C??. (b) To accept an answer. (c) To print out ?
Good? and then stop, if the answer is correct. To output the message ?try again? it
the answer is wrong. (d)To display the correct
answer when the answer is wrong even at the third attempt and stop.
Source Code
#include<stdlo.h>
lnt maln()
(
char s1 [25];
char s2[25]="DennisRitchie;
int n;
I/printt("Who is the inventor of 0?"):
printf("\nAnswer is:'):
scant("%s",s1);
n=strcmp(s1,s2);
lt(n|=0)
pr|ntf("\ntry again");
else
printt("\nGood");
retum 0:
l
Sample Input
DennlsRitchie
Sample Output
Answer is:
Good
Result
Thus, Program " Inventor C" has been successfully executed

course: C Spbject Code:


Q. Copy Count
Write a C program to copy one string to another string using loop. C program to
copy one string to another without using inbuilt library
function strcpy() and count total number of characters copied. How to copy one
string to another and count total characters copied with
and without using inbuilt string library function
Source Code
#include <stdio.h>
int maln()
(
char text1[100]. text2[100];
int i;
//prlntf('Enter any string: ");
scanf("/>s" ,text1 )1
I Copies text1 to text2 character by character '/
i=0;
whlle(text1[l]l='\0)
l
text2[i] = text1[i]2
i++Z
l
//Makes sure that the string is NULL terminated
text2[i] = '\0';
printf("\nFlrst strlng=%s",text1)l
printt("\nSecond strlng=%s",text2);
printf("\nTotal characters copied=/<>d", I);
return 0:
l
Sample Input
SRMUnlversity
Sample Output
F-rrst string=SRMUniversity
Second strlng=SFtMUnlversity
Total characters copied=13
Result
Thus, Program "Copy Count " has been successfully executed

Course: C Sybject Code:


Q. Concatenate Code
Write a C program to concatenate two different strings into single string. How to
concatenate two strings into one without using strcat()
library function. Adding two strings into one without using inbuilt library
function.C0ncatenation of two strings is the process of joining
them together to form a new string. Concatenation basically joins the second string
after first string. Concatenation is sometimes also
referred as binary addition of strings i.e. + operation. For example: Codefor + Win
= CodeforWin
Source Code
#|nclude <stdio.h>
#deflne MAX_SIZE 100
int maln()
i
char text1[MAX_SIZE]. text2[MAX_SlZE], output[MAX_SIZE];
rm i, 1;
// prlntf("\nEnter first string: ")1
scanf(%s".text1);
//printf('\nEnter second string: ");
scanf("/<>s"_.text2)2
i=0:
whlle(text1[l]l='\0)
{
outputfi] = text1[i]I
i++;
}
/ Copies text2 to output string '/
j =
whlle(text2[j]l='\0)
{
outputiq = text2[i];
i++;
]++;
i
//Make sure that the output is NULL terminated
output[l] = '\0':
printf(\nFlrst string=/>s", text1);
printf("\nSecond strlng=%s", text2);
printf("\nFinal concatenated string=%s". output);
return 0;
l
Sample Input
SRMUnlversity
LeamlngCentre
Sample Output
F-_llSt strlng=SFtMUnivers|ty
Second string=LeamingCentre
Hnal concatenated string=SRMUniversityLearningCentre
Result
Thus, Program " Concatenate Code " has been successfully executed

course: C Srbject Code:


Q. Conversion Code -01
Write a C program to convert lowercase string to uppercase string using inbuilt
string library function strupr()internally characters in C
are represented as an integer value known as ASCII value. Which means if we write A
or any other character it is translated into a
numeric value in our case it is 65 as ASCII value of A = 97. Here what we need to
do is first we need to check whether the given
character is lowercase alphabet or not. If it is lowercase alphabet just subtract
32 from it which will result in uppercase alphabet (Since
ASCII value of A=65, a=97 their difference is 97-65 = 32).
Source Code
#lncIude<stdlo.h>
#deflne MAX_SlZE 100 //Maximum size of the string
int maln()
I
char strlng[MAX_SlZE];
int i;
1" Reads a string from user '/
//prlntf('\nEnter your text:");
scanf("%s",strlng);
for(i=0; strlng[l]|='\0'; i++)
I
It
' If current character is lowercase alphabet then
convert It to uppercase.
'1
if(string[I]>='a' && string[i]<=z)
I
string[i] = strlng[l]-32;
I
l
printf("\nUppercase string:/>s",string);
return 0:
l
Sample Input
srmunlversity
Sample Output
Uppercase string:SRMUNlVEFISlTY
Result
Thus, Program " Conversion Code -01 " has been successfully executed

Course: C Spbject Code:


Q. Conversion Code -02
Write a C program to convert uppercase string to lowercase using inbuilt string
library function strlwr(). How to use strlwr library function
in C programming. Internally characters in C are represented as an integer value
known as ASCII value. Which means if we write a or
any other character it is translated into a numeric value in our case it is 97 as
ASCII value of a = 97. Here what we need to do is first we
need to check whether the given character is upper case alphabet or not. If it is
uppercase alphabet just add 32 to it which will result in
lowercase alphabet (Since ASCII value of A=65, a=97 their difference is 97-65 =
32).
Source Code
#lnclude <stdio.h>
#deflne MAX_SlZE 100 //Maximum size of the string
int maln()
l
char string[MAX_SlZE];
lnt i;
/ Reads strlng from user I
//prlntf('\nEnter any string:');
scanf('%s",strlng);
/fRuns a loop tlll last character of string
tor(i=0; strlng[l]l=\0'; l++)
{
if(string[l]>='A' && strlng[l]<='Z)
l
string[i] = string[i] + 322
l
l
printf("\nLower case string:%s", string);
return 0;
)
Sample Input
SRMUNIVERSITYLEARNINGCENTRE
Sample Output
Lower case stringzsrmuniversitylearningcentre
Result
Thus, Program " Conversion Code -02 " has been successfully executed

Course: C Srbject Code:


Q. Count a String
Write a C program to count total number of alphabets, digits or special characters
in a string using loop. How to find total number of
alphabets, digits and special characters in a string in C programming.
Source Code
#include <stdio.h>
#dene MAX_SlZE 100 //Maximum size of the string
lnt main()
l
char string[MAX_SlZE];
int alphabets, digits, others, I;
alphabets = digits = others = i = 0;
i Reads a string from user '1
//prIn(Enter any string:"):
scanf("%s,string);
/C
Checks each character of string
*/
whlle(string[i]l='\0')
l
if((strlng[l]>=a' && string[l]<='z') || (strlng[l]>='A' && strlng[i]<='Z'))
l
alphabets++;
}
else lf(string[i]>='0' && strlng[l]<=9)
{
digits++;
l
else
(
others++;
}
i++1
}
printf("\nAlphabets=%d", alphabets);
printf("\nDlgits=/ed", digits);
printf("\nSpecial characters=%d", others);
return 0:
l
Sample Input
SRM!Un|verslty@Leaming&Centre@1 1 13
Sample Output
Alphabets=27
Digits=4
Special characters=4
Result
Thus, Program "Count a String " has been successfully executed

course: C ibject Code:


Q. Reverse String- Without Library
Write a C program to find reverse of a string without library function.
Source Code
#include <stdio.h>
#include <string.h>
#deflne MAX_SlZE 100 //Maximum size of the string
lnt main()
l
char string[MAX_S|ZE], reverse[MAX_S|ZE];
int i, j, len;
1" Reads string from user '/
//pr|ntf("\nEnter any string:");
scanf("%s".string);
len = strlen(strlng);
l = 01
for(i=|en-1: l>=0; i--)
l
reverse[j] = string[l];
j++;
}
reverse[|] = \O';
pr1ntt("\nOriginal string=%s\n", string);
printf("Reverse string=/cs". reverse);
return 0;
l
Sample Input
SRMUniversity
Sample Output
Original string=SRMUniversity
Reverse string=ytlsrevinUMRS
Result
Thus, Program " Reverse String- Without Library" has been successfully executed

Course: C Stibject Code:


Q. Print Index
How to find all occurrences of a character in a given string using for loop in C
programming. Program to print all index of a character in a
given string.
Source Code
#include <stdio.h>
#lnclude<string.h>
#define MAX_SlZE 100 I/Maximum size of the string
int main()
l
char a;
char string[MAX_SlZE];
int i,len;
f/prlntt("\nEnter any character to searchz");
scanf("%c".&a);
//prlntf('\nEnter any stringZ):
scanf("%s",strlng)l
|en=strlen(string);
//Runs a loop tlll the NULL character is found
for(i=0; i<=len; i++)
l
if(string[i] == a)
{
printf("\n%c is found at index /0d". a, i);
l
l
return 0;
l
Sample Input
u
srmunlversity
Sample Output
u is found at index 3
Result
Thus, Program " Print Index " has been successfully executed

Subject Code:
Course: C H
Q. Maximum Frequency
How to nd highest frequency character in a string using loop in C programming.Find
frequency of each characters in the string and
store it in some array of integers. Find maximum element in the array. Maximum
element in the array will the be maximum occurring
character in the string.
Source Code
#inciude <stdio.h>
#deflne MAX_SlZE 100 //Maximum size of the string
#define MAX_CHARS 255 //Maximum characters allowed
int maln()
(
char string[MAX__SlZE];
int frequency[MAX_CHARS]; //Stores frequency of each character
int i = O, max;
int ascii;
//prlntf('Enter any string: ");
scanf(%s",string);
I Initializes frequency of all characters to 0 I
for(i=0: i<MAX__CHARS; l++)
{
frequency[|] = 0:
}
/' Finds frequency of each characters '1
i=0:
whlle(string[i] l= '\0')
{
ascii = (int)string[l];
frequency[asci|] += 1;
i++1
i
/' Finds maximum frequency '/
max = 02
for(i=0; i<MAX_CHARS; l++)
l
if(frequency[l] > frequency[max])
max = i;
}
printf("'\nHighest frequency of %c is %d tn", max, frequency[max]);
return 01
l
Sample input
srmuniversity
Sample Output
Highest frequency of i ls 2
Result
Thus, Program "Maximum Frequency" has been successfully executed

Subject Code:
Course: C 11
Q. Minimum Frequency
How to nd lowest frequency character in a string using loop in C programming
Source Code
#inciude <stdio.h>
#define MAX_SlZE 100 //Maximum size of the string
#deflne MAX_CHARS 255 //Maximum characters allowed
int maln()
i
char string[MAX_SlZE];
int frequency[MAX_CHAFtS]: /lStores frequency of each character
int i = O. min:
int ascli;
//printf('\nEnter any string:");
scanf("%s.string);
/' Initializes frequency of all characters to 0 I
for(i=0; i<MAX_CHARSI |++)
{
l
frequency[|] = 0:
I Finds frequency of each characters /
i=0;
wh|ie(string[i] != '\0')
{
ascii = (int)string[i]:
frequency[asciq += 1;
i++:
} .
I Finds minimum frequency I
min = 0;
f0r(i=0; i<MAX_CHAFtS: i++)
{
if(frequency[i] i= 0)
{
if(frequency[min] == O || frequency[|"i < frequency[min])
min = i;
i
i
printf("\nLowest frequency of %c is /od", min. frequency[min]);
return 0;
l
Sample Input
madam
Sample Output
Lowest frequency of d is 1
Result
Thus, Program " Minimum Frequency " has been successfully executed

Subject Code:
Course: C H
Q. Frequency of each
Write a C program to count frequency of each character in a string using loop
Source Code
#Include <stdio.h>
#lnclude <string.h>
#defIne MAX_SlZE 100 //Maximum size Of the string
lnt maln()
(
char string[MAX_SlZE];
lnt i, len;
lnt frequency[26];
/ Reads a strlng from user '1
//pr|ntf(Enter any string: ");
scanf( />s",strlng);
len = strlen(strlng);
/ Initializes frequency of each character to 0 '/
for(i=0; i<26I i++)
{
lrequency[|] = 03
}
/' Fil'1dS tOt3| number Of OOCUWBHCQS Of each character '/
for(i=0; i<len; i++)
{
I If the current character is lowercase alphabet '/
if(string[l]>='a' && string[i]<=z)
(
frequency[string[l] - 97]++;
l
else lf(string[l]>='A && string[|]<=Z')
l
frequency[strlng[i] - 65]++;
l
l
/R
Prints the frequency of all characters In the string
I
printf("\nFrequency of all characters in the given string: \n");
f0r(i=0; i<26; i++)
{
/' If the current character ls In given string I
if(trequency[i]l=0)
l
printf("%c = %d\n". (i+97), frequency[i]);
}
l
return 0:
l
Sample Input
srmunlversitylearningcentre
Sample Output
Frequency of all characters in the given string:
a=1
=1
<<Cm":3_'_'(Q'DO
_.__.N|\)-~,p_ _.,;>
=3
=1
Result
Thus, Program " Frequency of each" has been successfully executed

course: C ?:.lb]eC\ Code:


Q. Alphabetical Order
Write a program which will read a string and rewrite it in the alphabetical order.
For example, the word STRING should be written as
GINRST.
Source Code
#include<stdlo.h>
#Include<strlng.h>
lnt maln()
l
char a[30],temp;
int n=0_j,i;
//printt("mEnter the string:");
scant("%s",a);
while(a[n]l='\0)
l
n++;
l
for(i=0;i<n;i++)
l
for(j=0;j<n-i-1;j++)
(
"(a[il>ali+11)
l
temp=a[[];
a[i]=a[i+1]I
a[]+1]=temp;
l
l
l
printf("\nThe string in alphabetical order is:");
for(l=0;i<n;l++)
l
printf("/=c',a[i]);
l
retum 0:
l
Sample Input
string
Sample Output
The strlng in alphabetical order is:ginrst
Result
Thus, Program " Alphabetical Order " has been successfully executed

Subject Code:
Course: C 11
Q. Remove String 1st Occurrence
Write a C program to read any string from user and remove first occurrence of a
given character from the string
Source Code
#include <stdio.h>
#lnclude <string.h>
#dellne MAX_SlZE 100 //Maximum size of the string
/" Function declaration I
void removeFirst(char , const char);
lnt main()
f
char string[MAX_SlZE];
char toRemove;
/!printf("\nEnter character to remove from string: ");
toRemove = getchar();
//pr1ntf("\nEnter any string: ")1
scanf(%s",strlng);
removeFirst(string, toRemove):
printf("\nOutput:/<>s"_ string);
return 0:
l
/..
' Function to remove rst occurrence of a character from the string.
'/
void removeFlrst(char string, const char toRemove)
t
lnt i;
int len = strlen(string);
i=0:
1' Run loop until the rst occurrence of the character is not found '1
whlle(klen && strlng[i]|=toRemove)
i++;
/
Shift all characters right to the posltlon found above to one place left
*1
whlle(klen-1)
{
string[i] = string+1];
i++;
1
/' Make the last character null '/
string[i] = '\0';
l
Sample Input
l
srmuniversitylearningcentre
Sample Output
Output:srmunversltyleamingcentre
Result
Thus, Program " Remove String 1st Occurrence" has been successfully executed

Subject Code:
Course: C 11
Q. Remove All occurrence
C program to remove all occurrences of a character from the string
Source Code
#Include <stdio.h>
#lnclude <string.h>
#deflne MAX_SlZE 100 //Maximum size of the string
/" Function declaration /
void removeLast(char , const char);
int main()
i
char string[MAX_SlZE];
char toRemove;
/fprintf["Enter character to remove from string:");
toRemove = getchar();
//printf("\nEnter any string:");
scanf("%s" ,strl ng);
removeLast(strlng, toRemove);
printt("\nOutput:%s",string);
return 0;
l
1..
' Function to remove last occurrence of a character from the string.
'/
void removeLast(char ' stnng, const char toRemove)
l
int l, lastPosition;
int len = strlen(string);
|astP0sition = -1;
i=0;
whlie(i<ien)
{
if(string[i] == toFtemove)
l
IastPosition = I;
}
i++I
1
it(lastPosition l= -1)
{
i = lastPosition:
It
Shift all characters right to the position found above to left
*1
whi|e(i<len-1)
{
string[i] = string[i+1];
i++;
}
l
I Make the last character null '/
strlng[i] = '\0';
l
Sample Input
a
madam
Sample Output
Outputmadm
Result
Thus, Program " Remove All occurrence has been successfully executed

Subject Code:
Course: C 11
Q. Remove String 1st Occurrence
Write a C program to read any string from user and remove rst occurrence of a
given character from the string
Source Code
#include <stdio.h>
#define MAX_SlZE 100 //Maximum size of the string
/ Function declaration '/
void replaceF|rst(char ' string, char toReplace. char replacewlth);
int main()
l
char string[MAX_SlZE], toReplace, replacewlth:
//printf('Enter any strlng:");
scanf("%s",string)1
//printt('Enter character to replacet");
soant(' %c". &toReplace);
1/ prlntt(Enter character to replace '/oC' wlth:". toReplace);
scanf(" %c", &replaceWith);
printt("\nString before replacing:%s", string);
replaceFirst(strlng, toReplace_. replacewlth):
printt("\nString after replacing:/us", string);
return 0:
i
PO
' Replaces the first occurrence of a character
' with another in given string.
I
void replaceFlrst(char string, char toReplace, char replacewlth)
(
int i=OI
/ Runs till the end of string '/
whlle(string[i] l= '\0')
{
I If an occurrence of character ls found "/
if(string[|] == toReplace)
t
string[i] = replaceVlth;
break:
}
i++;
l
l
Sample Input
srmunaversityiearningcentre
a
i
Sample Output
String before replacingzsrmunaversityleamingcentre
String after replacing:srmuniversitylearningcentre
Result
Thus, Program " Remove String 1st Occurrence" has been successfully executed

Course: C Spbject Code:


Q. Character Extract
Write a program to extract a portion of a character string and print the extracted
string. Assume that m characters are extracted, starting
with the nth character.
Source Code
#incIude<stdlo.h>
#dene MAX 50
int ma|n()
i
char Str1[MAX]:
int l,m,n.j;
//printf("Enter A String:");
scant("%s".Str1);
!1'printt("\nEnter Number of Characters Which You Want to Extract:");
scanf("%d".&m):
I/printf("\nEnter Beginning Index from Which U Want to Extract):
scanf("%d",&n):
printf("\nExtracted String is:");
for(i=n-1;I<m+n-1;i++)
i
printf("%c'.Str1[i]);
i
retum O;
i
Sample Input
SRMUniversityLeamingCentre
10
5
Sample Output
Extracted String is:niversityL
Result
Thus, Program " Character Extract" has been successfully executed

course: C Srbject Code:


Q. Rupee Name
Write a program that reads the cost of an item in the form RRRR.PP (where RRRR
denotes rupees and PP denotes paise) Refer
sample input and output.
Source Code
#lnclude<stdlo.h>
rm maln()
l
oat Cost,Pai,Re,j:
lnt Rup,i,R;
//printf("\nEnter Cost of an ITEM 1');
scanf("%f",&Cost);
Rup = Cost;
Pal = (Cost - Rup)'100;
i=Rup/100;
switch(l)
(
case 1: prlntf("ONE HUNDRED "); break:
case 2: printf('TWO HUNDRED "); break;
case 3: printt('THREE HUNDRED "); break;
case 4: prlntf("FOUR HUNDRED ); break;
case 5: printt("FlVE HUNDRED "): break;
case 6: printf("SlX HUNDRED "); break:
case 7: prlntt("SEVEN HUNDRED "); break;
case 8: printt("ElGHT HUNDRED "); break;
case 9: prlntf("NlNE HUNDRED "); break:
l
l=Rup%100;
R=l/10:
Re=(oat)l/1 0;
switch(R)
l
case 1: print1("TEN"); break:
case 2: prlntf('TWENTY "); break;
case 3: printf("THlRTY '); break;
case 4: printf("FOURTY "); break;
case 5: prlntf("FlFTY "); break;
case 6: prlntt("SlXTY "); break;
case 7: prlntf("SEVENTY "); break:
case 8: printf("ElGHTY "); break;
case 9: printf("NlNETY "); break;
l
R=(Re-R)'10;
switch(R)
(
case 1: prlntf("ONE"); break;
case 2: prlntf("TWO "); break;
case 3: prlntt('THREE "); break;
case 4: printf("FOUR "); break;
case 5: prlntf("FlVE ); break:
case 6: prlntf("SlX )1 break;
case 7: prlntt("SEVEN "); break;
case 8: prlntf("ElGHT "); break:
case 9: printt("NlNE "); break;
l
printt("AND PAISE ");
i=Pal/10;
Re=(oat)PaI/10;
R=(Re-l)10:
switch(l)
l
case 1: prlntt("TEN): break;
case 2: prlntf("TWENTY "); break;
case 3: prlntf("THlRTY "); break;
case 4: printf("FOURTY "); break;
case 5: prlntf("Fll-TY "); break;
case 6: printf("SlXTY "); break;
case 7: prIntf("SEVENTY "); break;
case 8: prlntt("ElGHTY "); break;
case 9: prlntt("NlNETY "); break;
l
switch(R)
(
case 1: prlntf("ONE"); break:
case 2: prlntf("lWO "); break:
case 3: printf("THREE "); break;
case 4: prlntf("FOUR "); break;
case 5: prlnt1("FlVE '); break;
case 6: prlntf("SlX "): break;
case 7: prlntf("SEVEN "); break;
case 8: printf("ElGHT "); break;
case 9: prlntf("NlNE ); break;
l
retum O2
l
Sample Input
104.3
Sample Output
ONE HUNDRED FOUR AND PAISE THIRTY
Result
Thus, Program " Rupee Name " has been successfully executed

course: C Spbject Code:


Q. String Compare
Write a program to read to strings and compare them using the function strcmp() and
print a message that the first string is equal, less
or greater than the second one.
Source Code
#include<stdlo.h>
#def|ne MAX 50
int maln()
t
char Str1[MAX],Str2[MAX]:
//printt("\nEnter First String:'):
scanf("%s",Str1 );
fush(stdin);
//printt("\nEnter Second String:");
scanf("%s".Str2);
it(strcmp(Str1 ,Str2)==0)
printt("\nB0th Strings are Equal");
else lf(strcmp(Str1.Str2)<0)
printt("\nFirst String is Less Than Second String"):
else
printt("\nFirst String is Greater Than Second String");
retum 0;
)
Sample Input
SFtMUnlversity
SRM
Sample Output
First String is Greater Than Second String
Result
Thus, Program "String Compare " has been successfully executed

course: C Srbject Code:


Q. Consecutive String Copy
Write a program that will copy m consecutive characters from a string s1 beginning
at position n into another string s2
Source Code
#include<stdlo.h>
#define MAX 50
void main()
(
char Str1[MAX],Str2[MAX];
lnt i,m,n,];
/iprintf("\nEnter A Str|ng:"):
scanf("/<>s",Str1 );
/.'printf("\nEnter Number of Characters Which You Want to Copy:");
scanf("%d'.&m):
//printt("\nEnter Beginning Index from Which You Want to Copyz");
scant("%d'.&n)I
tor(l=n-1.j=0:i<m+n;l++.j++)
i
Str2[j]=Str1[|];
i
Str2[m]='\0'2
printf("\nCopied String is:%s".Str2);
l
Sample Input
SRMUnlversity
5
1
Sample Output
Copied String ls:SRMUn
Result
Thus, Program "Consecutive String Copy" has been successfully executed

course: C Srbject Code:


Q. Student Directory
Write a program to create a directory of students with roll numbers.The program
should display the roll number for a specified name and
vice-versa.
Source Code
#include<stdlo.h>
#dene MAX 50
int ma|n()
l
char Stu_Name[MAX][MA)(],Name[MAX];
int Ro||_No[MAX],n,l.Roll.lndex;
//print1(\nHow Many Student Name You Want to Enterz");
scant("%d",&n);
//printf("\nEnter Roll No and Students Namet");
for(i=0;i<n;l++)
l
scanf("%d".&Roll_No[l])1
scanf("%s". Stu_N ame[i]);
l
//printf("\nEnter Student Roll No which You want to Search:");
scanf("%d,&RolI);
for(l=0;i<n;l++)
l
lt(Roll==Roll_No[l])
l
lndex=i:
l
l
printf("\nName of Student is: />s whose Roll No is:%d',Stu_Name[lndex],Roll);
/iprlntt("\nEnter Student Name which You want to S83lChI")_Z
scan1("%s",Name);
for(l=0:i<n;i++)
l
lf(strcmp(Stu_Name[l],Name)==0)
l
lndex=l;
l
l
printt("\nRol| No of Student:/ed whose Name is:
%s",Roil_No[lndex],Stu_Name[lndex])1
retum O;
l
Sample Input
5
100 KirthigaDevi
101 JohnBlesswin
102 Selvamary
103 Chrlsthuraj
104 Rajeevsukumaran
104
KirthigaDevl
Sample Output
Name of Student ls: Rajeevsukumaran whose Roll No is:104
Roll No of Student:100 whose Name is:KlrthlgaDevi
Result
Thus, Program "Student Directory" has been successfully executed

Course: C 11
Subject Code:
Q. String Patt
Given a string
Source Code
#include<stdio.h>
mt main()
{
char Str[]="123456
int i,j.k,l;
f0|'(i=0;I<5;i++)
{
for(k=4;k>i;k--)
(
)
f0r(j=0.|=|:j<=i 1+1"
(
printf("/>c.Str[l]);
)
l=l-22
for(k=0;k<i;k++,l--
printf("/>C".Str[l])I
printf("\n");
)
}
retum 0:
)
Sample Input
0
Sample Outpu
1
232
34543
4567654
567898765
Resuh
Thus, Program
ern
cha
789
_l++)
I
NS
rstr[] =123456789; Write a program that displays the following: 1 2 3 2 3 4 5 4 3 4
5 6 7 6 5 4 5 6 7 8 9 8 7 6 5
tring Pattern" has been successfully executed

course: C Spbject Code:


Q. String Length
Write a C program to find length of a string using loop. How to find length of a
string without using in-built library In C there is a general
concept that every string must terminate with a special character that is NULL
character which is also escaped. Hence we use a this
basic concept to find length of string. What we need to do is traverse entire
string character by character till a NULL character is found
and in each iteration increment the counter value.
Source Code
#lnclude <stdio.h>
int maln()
l
char text[100]; I Declares a string of size 100 "/
Int index= 0;
//prlntf("Enter any strlng: ");
scanf(%s",text):
while(text ndex] l='\0)
l
lI'ld8X+1-I
l
printf("\nLength of %s=%d", text, index);
return 0;
l
Sample Input
SRMUniversityLeamingCentre
Sample Output
Length of SFtMUn|versityLeamingCentre=27
Result
Thus, Program "String Length" has been successfully executed

course: C Spbject Code:


Q. Turbo Sort
Given the list of numbers, you are to sort them in non decreasing order. lnputt ?
the number of numbers in list, then t lines follow [t <=
10"6]. Each line contains one integer: N [0 <= N <= 10"6] Output Output given
numbers in non decreasing order.
Source Code
#include <stdio.h>
Int array[1000001] = {O};
int main(){
Int i,j;
scanf("/=d",&j)Z
int x;
for (i=O:i<j:i++){
scanf("/>d",&x);
array[x]++;
l
for (i=O;i<1000001;l++){
wh||e(array[|]>0){
prlntt(%d\n",i);
arrayfl]--;
}
l
retum 0;
l
Sample Input
6
543211
Sample Output
U'1J>OJi\)**
Result
Thus, Program "Turbo Sort" has been successfully executed

course: C Srbject Code:


Q. Chef And Operators
Chef has just started Programming, he is in first year of Engineering. Chef is
reading about Relational Operators.Relati0nal Operators
are operators which check relationship between two values. Given two numerical
values A and B you need to help chef in finding the
relationship between them that is, First one is greater than second or, First one
is less than second or, First and second one are equal.
Input First line contains an integer T, which denotes the number of test cases.
Each of the T lines contain two integers A and B. Output
For each line of input produce one line of output. This line contains any one of
the relational operators <,>,= Constraints 1 <= T <=10000
1 <= A, B <=1000000001
Source Code
#lnclude<stdlo.h>
Int main()
l
int t,a.b1
scanf("%d",&t)3
whlle(t--)
{
scanf("%d/<>d".&a,&b);
it(a>b)
printf("\n>");
lf(a<b)
printf("\n<");
lf(a==b)
printf("\n=");
}
return 0;
l
Sample Input
3
1020
2010
1010
Sample Output
<
>
Result
Thus, Program " Chef And Operators" has been successfully executed

Course: C Srbject Code:


Q. Array Mode
Write a program to find the mode of the elements in the array. The mode in a list
of numbers refers to the list of numbers that occur most
frequently. It is important to note that there can be more than one mode and if no
number occurs more than once in the set, then there is
no mode for that set of numbers. Input and Output Format: Input consists of n+1
integers where n corresponds to the number of
elements in the array. The first integer corresponds to n and the next n integers
correspond to the elements in the array. Refer sample
input and output for formatting specifications. Assume that the maximum number of
elements in the array is 20. Assume that in the input
dataset there is 1 mode or no mode at all. All text in bold corresponds to input
and the rest corresponds to output.
Source Code
#include<stdlo.h>
#lnc|ude<std||b.h>
lnt createArray(int);
void readElement(lnt,int ');
void arrayMode(int,lnt );
lnt main()
f
lnt 'a,n;
//printf("Enter the number of elements in the arrayln");
scanf("%d".&n):
a=createArray(n);
readEIement(n,a);
printt("The mode of the array ls");
arrayMode(n,a);
retum O;
l
lnt "createArray(int n)
l
lnt a;
a=(int ")ma|loc(nsizeof(Int));
retum a;
l
void readElement(lnt n,int 'a)
l
lnt ii
//printf("Enter the elements in the array\n");
for(i=0;i<n;I++)
t
scanf("%d",a+i);
l
l
void arrayMode(int n.int a)
l
lnt l,j,c=0,k;
for(i=0:i<n;l++)
l
for(j=i+1;]<n;j++)
l
"('(a+i)==(a+i))
(
mm
k=(a+i);
l
l
l
"(C==0)
(
printf(" none");
l
else if(c>0)
(
printf(" %d",k):
l
l
Sample Input
5
24235
Sample Output
The mode of the array ls 2
Result
Thus, Program "Array Mode " has been successfully executed

Course: C Srbject Code:


Q. UPPER TRIANGULAR MATRIX
An upper triangular matrix is a square matrix in which all the elements below the
diagonal are zero. That is, all the non-zero elements
are in the upper triangle: Write a C program to find whether a given matrix is an
upper triangular matrix or not. Input Format: The input
consists of (nn+1) integers. The first integer corresponds to the number of
rows/columns in the matrix. The remaining integers
correspond to the elements in the matrix. The elements are read in rowwise order,
first row first, then second row and so on. Assume
that the maximum value of m and n is 5. Output Format: Print yes if it is an upper
triangular matrix . Print no if it is not an upper triangular
matrix
Source Code
#include<stdlo.h>
#lnclude<stdl|b.h>
int "createArray(int);
void getE|ements(int",lnt);
void triangu|arMatrix(int,int);
int main()
(
Int "a,n;
scanf("/<>d".8tn)Z
a=createArray(n);
getElements(a,n);
triangularMatrh(a,n)2
retum 0;
l
int "'createArray(int n)
(
lnt i.a;
a=(Int' )malloc(n*sizeof(int')):
for(i=0;i<n;i++)
l
'(a+|)=(int')malloc(nsizeof(int));
l
retum a;
l
void getE|ements(int "a,lnt n)
(
int i,j;
for(|=0;i<n;l++)
(
for(j=0:j<n;j++)
l
scanf("%d".'(a+I)+j);
l
l
l
void triangu|arMatrix(int "a,int n)
i
Int i,j;
for(|=0:i<n;l++)
l
for(j=0;j<n;j++)
(
1t<i==1>
(
break;
l
else lf(('('(a+|)+j))|=0)
l
printf("no"):
retum:
l
l
l
printf("yes"):
l
Sample Input
2
1 2
0 3
Sample Output
yes
Result
Thus, Program " UPPER TRIANGULAR MATRIX " has been successfully executed

Subject Code:
Course: C H
Q. Array - Sum of Even Numbers
Write a program to nd the sum of the even numbers present in an array using
recursion. Input and Output Format: Refer sample input
and output for formatting specifications.
Source Code
#lnclude<stdio.h>
#lnclude<stdllb.h>
lnt sumEvenArray(int a.Int li,int size)
(
lnt s=0;
lt(slze==0)
l
retum s;
l
//printt("%d\n",|l);
lf('(a+(size-1))%2==O)
l
s=s+'(a+(s|ze-1)):
//printf("%d\n",s);
l
retum s+(sumEvenArray(a,li,(size'1)));
l
Int maln()
l
lnt "a,ll,size,b;
//printf("Enter the number of elements in the array\n");
scanf("%d".&slze);
//printt("Enter the elements in the array\n");
a=(int')malloc(size'sizeof(int));
for(Ii=0:li<size;|i++)
(
scant("%d".(a+li));
l
b=sumEvenArray(a,li,size)1
printt("The sum of the even elements ln the array is:%d",b);
retum 0;
)
Sample Input
5
4681012
Sample Output
The sum of the even elements in the array is:40
Result
Thus, Program "Array - Sum of Even Numbers" has been successfully executed
course: C Srbject Code:
Q. Recursion 8 : Maximum Element in Array
Write a program to find the maximum element in an array using recursion. Input and
Output Format: Input consists of n+1 integers
Refer sample input and output for formatting specifications. All text in bold
corresponds to input and the rest corresponds to output
Source Code
#include<stdio.h>
#lnclude<stdl|b.h>
int max=0;
lnt ndMaxElement(int arr,int size)
l
li(slze==0)
(
retum max;
l
ii('(arr+(size-1))>max)
l
max=('(arr+(slze-1)));
//printf("max %d\n'.max);
l
else
(
max=max;
/rprintf("max %d\n'_max):
l
retum flndMaxElement(arr,(slze~1));
l
int main()
l
int arr,size,i;
//printf("Enter the size of the array\n");
scanf("%d".&slze)2
//printf("Enter %d elements of an array\n",size);
arr=(int ')malloc(size'sizeof(int))I
for(i=0;i<size;i++)
l
scanf("%d",(arr+i));
l
findMaxE|ement(arr,slze);
printf("Maxlmum element in the array is %d".findMaxE|ement(arr.slze));
retum 0;
)
Sample Input
6
251742
Sample Output
Maximum element in the array is 7
Result
Thus, Program "Recursion 8 : Maximum Element in Array" has been successfully
executed

Course: C Szibject Code:


Q. Recursion 7 : Sum of elements in Array
Write a program to compute the sum of elements in an array using recursion. Input
and Output Format: Input consists of n+1 integers
Refer sample input and output for formatting specifications. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#include<stdio.h>
#lnclude<stdl|b.h>
int ndSum(int 'a,int n)
(
mt s=O;
ll(n==0)
(
retum $1
l
s=s+*(a+(n-1));
//printf("%d\n,s);
retum s+flndSum(a,(n-1));
l
Int maln()
t
Int n,a.l,cI
//printf("Enter the number of elements\n');
scanf("%d'.&n);
//printf("Enter the elements in the array\n");
a=(Int')malIoc(n'sizeof(int));
for(i=0:i<n;i++)
(
scanf("%d".(a+l));
l
c=findSum(a.n);
printf("The sum of the elements in the array is %d".c);
retum 0;
l
Sample Input
5
54321
Sample Output
The sum of the elements in the array ls 15
Result
Thus, Program " Recursion 7 : Sum of elements in Array" has been successfully
executed

course: C Spbject Code:


Q. Recursion 5 : Number of digits
Write a program to find the number of digits in a number using recursion. Input and
Output Format: Input consists of a nonnegative
integer. Refer sample input and output for formatting specifications. All text in
bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude<stdlo.h>
#include<stdl|b.h>
int computeNum(int n)
f
int c=0;
lf(n%10==n)
l
retum 1:
l
lf(n%10l=0)
l
C++;
l
c=<:+computeNum(n/10);
retum c:
l
int main()
l
Int n,b;
//printf("Enter the value of n\n");
scanf("%d",&n):
b=computeNum(n);
printf("The number of digits in %d is />d',n,b);
retum 0;
l
Sample Input
123
Sample Output
The number of digits in 123 is 3
Result
Thus, Program "Recursion 5 : Number of digits" has been successfully executed

course: C Spbject Code:


Q. Recursion 4 : Sum of digits
Write a program to find the sum of digits in a number using recursion. Input and
Output Format: Input consists of a nonnegative integer
Refer sample input and output for formatting specifications. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#lnclude<std|o.h>
#lnclude<stdl|b.h>
lnt computeSum(int n)
i
lnt s:
Int k=n;
while(k)
l
s=k%10;
retum s+computeSum(k/10);
l
l
int main()
l
Int n;
//printf("Enter the value of n\n");
scanf("%d",&n):
computeSum(n);
printf("The sum of digits in %d is /<>d",n,computeSum(n));
retum 0;
l
Sample Input
43
Sample Output
The sum of digits in 43 is 7
Result
Thus, Program "Recursion 4 : Sum of digits" has been successfully executed
course: C Spbject Code:
Q. Recursion 3 : Compute a'\n
Write a program to compute a"n (a power n) using recursion. Input and Output
Format: Input consists of 2 integers. Refer sample input
and output for formatting specifications. All text in bold corresponds to input and
the rest corresponds to output.
Source Code
#lnclude<std|o.h>
#lnclude<stdl|b.h>
lnt computePower(int a,int n)
l
lf(n==O)
(
retum 1;
l
else if(n==1)
l
retum a;
l
retum computePower(a,n-1)'a;
l
lnt maln()
(
Int a,n;
//printf("Enter the value of a\n");
scanf("%d".&a);
//printf("Enter the value of n\n");
scanf("%d".&n);
compute Power(a, n);
printf("The value of /od power /od is /ed",a,n,computePower(a.n));
retum 0;
l
Sample Input
2
8
Sample Output
The value of 2 power a is 256
Result
Thus, Program "Recursion 3 : Compute a'\n" has been successfully executed

Course: C frbiect co
de:
Q. Factorial Using R
Write a program to co
sample input and out
P
Source Code
#include<stdio.h>
#lnclude<std||b.h>
int computeFactorial(int n)
(
lf(n==1||n==O)
(
retum 1 ;
l
else
(
retum n'computeFactorlal
l
l
Int main()
(
Int n;
//printf("Enter the value of
scanf("/<>d",&n);
computeFactorial(n);
printf("The factorial of %d
retum 0;
l
Sample Input
5
Sample Output
The factorial of S is 120
Result
Thus, Program "Fact
("-1)
CCU
mp
ut f
n\n");
is /<>d
oria
rsion -1
ute the factorial of a number using recursion. Input and Output Format Input
consists of an integer Refer
or formatting specifications. All text in bold corresponds to input and the rest
corresponds to output
_.n,computeFactoria|(n));
I Using Recursion -1" has been successfully executed

course: C Srbject Code


Q. Factorial of a number
Write a program to find the factorial of a number using functions Input Format
Input consists of 1 integer Output Format Output
consists of a single integer Refer sample output for formatting details
Source Code
#lnclude<std|o.h>
#include<string.h>
int tactorial(|nt);
int main()
l
Int n,fact;
scant("%d".8-n);
fact=factoriai(n);
printt("%d",fact):
retum 0;
l
int factorial(|nt n)
i
int i_.fact=1;
for(|=1;i<n+1;i++)
l
fact=fact'i;
//printf("%d\n",fact)I
l
retum tact;
)
Sample Input
3
Sample Output
s
Result
Thus, Program " Factorial of a number" has been successfully executed

course: C Spbject Code:


Q. Functions-Lucky String
Write a program to find whether the given string is Lucky or not. A string is said
to be lucky if the sum of the ascii values of the
characters in the string is even. Refer function specifications for the function
details. The function accepts a pointer to a string and
returns an int. The return value is 1 if the string is lucky and 0 otherwise. Input
and Output Format: Input consists of a string. Assume
that all characters in the string are lowercase letters and the maximum length of
the string is 100. Refer sample input and output for
formatting specifications. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#lnclude<stdlo.h>
#lnclude<string.h>
int checkLucky(char ');
int checkLucky(char *a)
l
lnt sum=0,l;
for(l=0;a[!='\0':i++)
(
sum=sum+a[l];
)
lf((sum%2)==0)
(
retum 1 ;
l
else
l
retum 0;
l
l
lnt main()
l
int i;
char a[100],sum;
//printf("Enter the input string\n");
scanf("%s",a);
for(i=0;a[l='\0';i++)
l
printt("/>c".a]);
l
sum=oheckLucky(a);
lf(sum==1)
l
printt(" is lucky);
l
else
l
printt(" is not lucky");
l
retum 0;
l
Sample Input
anltha
Sample Output
anltha is not lucky
Result
Thus, Program " Functions-Lucky String " has been successfully executed

course: C Spbject Code:


Q. LOWER TRIANGULAR MATRIX
A lower triangular matrix is a square matrix in which all the elements above the
diagonal are zero. That is, all the non-zero elements are
in the lower triangle: Write a C program to find whether a given matrix is a lower
triangular matrix or not. Input Format: The input consists
of (n"n+1) integers. The first integer corresponds to the number of rows/columns in
the matrix. The remaining integers correspond to the
elements in the matrix. The elements are read in rowwise order, first row first,
then second row and so on. Assume that the maximum
value of m and n is 5. Output Format: Print yes if it is a lower triangular
matrix . Print no if it is not a lower triangular matrix.
Source Code
#lnclude<stdlo.h>
#lnclude<stdl|b.h>
lnt createArray(int);
void getEIements(int",lnt);
void triangu|arMalrix(int",int);
Int maln()
l
int "a,n;
scant("%d".&n)2
a=createArray(n);
getElements(a,n);
triangularMatrh(a,n)2
retum 0;
l
int "'createArray(int n)
l
lnt "a,i:
a=(Int")malloc(n'sizeof(int'))1
for(l=0:i<n;l++)
l
"(a+l)=(lnt')ma||oc(nsizeof(int));
l
retum a:
l
void getE|ements(int"a,int n)
t
int L];
for(l=0:i<n;l++)
l
for(j=0;j<n;j++)
l
scanf("%d".'(a+l)+j);
l
l
l
void triangularMatrix(int"a,int n)
l
lnt L];
for(j=0:j<n;j++)
l
for(l=0;i<n;l++)
l
Hr(*('<a+i>+1>>==@&&<1>i>>
l
//printf("%d ",j);
//printf("%d\n",i);
//printf("%d'.('('(a+i)+j)));
l
else if((('((a+i)+j))!=0)&&(j>i))
l
prlntt("no");
return;
l
l
l
printf(yes");
l
Sample Input
2 1 0 2 a
Sample Output
yes
Result
Thus, Program " LOWER TRIANGULAR MATRIX " has been successfully executed

Course: C lbiect
Code:
Q. SYMMETRIC M
A symmetric matrix
or not. Input Forma
second integer cor
The elements are r
Source Code
#lnclude<stdlo.h>
#lnclude<stdl|b.h>
ATRIX using Function
is a square matrix that is equal to its transpose. Write a C program to find
whether a given matrix is a square matrix
t: The input consists of (m*n+2) integers. The first integer corresponds to m, the
number of rows in the matrix and the
responds to n, the number of columns in the matrix. The remaining integers
correspond to the elements in the matrix.
ead in rowwise order, first row first, then second row and so on. Assume that the
maximum value of m and n is 10.
int "createArray(int,lnt);
void getElements(int",i
void symmetrlcMatrix(in
int ma|n()
t
int "a.rows,columns;
scanf("%d".&rows);
scanf("%d',&co|umns);
a=createArray(rows,co|
//b=createArray(rows,oo
getElements(a,rows,co|
symmetricMatr|x(a,rows
retum 0;
i
int "createArray(int row
t
int i,"a;
a=(int)ma||oc(rows'slz
for(i=0;i<rows;i++)
i
'(a+i)=(int')ma|loc(colu
i
retum a;
i
void getElements(int "
(
int l,j;
for(l=0;i<rows;I++)
l
for(j=0:j<co|umns;]++)
(
scanf("%d'.('(a+i)+]));
)
)
)
void symmetrlcMatrix(ln
(
int i,j,c=0;
for(i=0;i<rows;i++)
(
for(j=0:j<co|umns;]++)
i
"l(('(8+i)+i))==(('(a+l
(
c++;
i
l
l
//printf("%d".c);
lf(c==(rowsco|umns))
(
printf("Symmetric");
l
else
t
printf("Not Symmetric)
l
l
Sample Input
2
2
4 5
5 4
Sample Output
Symmetric
Result
Y
Thus, Program "S
nt,int);
t",int,lnt);
umns);
lumns);
UmnS)Z
,columns);
s,int columns)
eof(int))I
mns'(sizeof(lnt)));
a,Int rows,int columns)
t "a,int rows.int columns)
)+i)))
s
MMETRIC MATRIX using Function" has been successfully executed

Course: C Spbject Code:


Q. UNIFORMITY MATRIX using Function
Uniformity matrix is a matrix in which all the elements in the matrix are either
completely even or completely odd
Source Code
#lnclude<stdIo.h>
#include<stdlib.h>
int "'createArray(int)I
void getElements(int",lnt);
void uniformityDlagona|s(int",lnt)I
Int main()
l
lnt "'a,n;
scanf("%d'.&n);
a=createArray(n);
getElements(a,n);
uniformityDiagonaIs(a,n);
retum 0;
l
lnt "createArray(int n)
l
int "'a,i;
a=(Int")mal|oc(n'sizeof(int'))I
for(i=0;i<n;l++)
l
'(a+i)=(int')malloc(nsizeot(int));
l
retum a;
l
void getEIements(int "a,int n)
l
lnt l,j;
for(l=0;i<n;l++)
l
for(j=0;j<n;j++)
l
scanf("%d".('(a+l)+]));
l
l
l
void uniformityDlagonals(int a,int n)
l
int l,j,b=0.c=0,d,e;
for(i=0;i<n;l++)
l
d=0:
for(j=0;j<n;j++)
l
"(i==l)
(
<1=(('(a+i)+ll);
lf((d==e)&&(d!=0))
l
printt("no");
retum;
l
l
l
e=d;
l
for(i=0;i<n;i++)
l
for(j=0;j<n;j++)
l
1r<(<'<'(a+i)+1>>%2==<>>>
l
C++;
l
else
l
b++;
l
// prlntf("%d\n",e);
l
l
"(==("'"ll|b==("'"l)
(
printf("yes");
l
6|S6
l
printf("no");
l
l
Sample Input
45
54
Sample Output
HO
Result
Thus, Program " UNIFORMITY MATRIX using Function" has been successfully executed

Course: C Srbject Code:


Q. DIAGONAL MATRIX
Diagonal Matrix.A square
number, including 0. Write
(nn+1) integers. The first
elements in the matrix. Th
value of m and n is 5. Out
Source Code
#|nclude<stdlo.h>
#lnclude<stdl|b.h>
int "create/\rray(int):
void getE|ements(int",lnt);
void diagonalElements(int",int);
lnt main()
l
int "'a,n;
scanf("%d',&n);
a=createArray(n);
getElements(a.n);
diagonalE|ements(a,n);
retum O;
l
int "createArray(int n)
i
Int i,"a;
a=(Int")ma|loc(n'sizeof(int'))I
for(i=0;i<n;i++)
f
(a+l)=maIloc(nsizeof(int));
l
retum a;
l
void getE|ements(int "a,lnt n)
l
int i,j;
for(l=0;i<n;l++)
f
tor(j=0;j<n;j++)
f
scanf("%d'.(a+i)+j);
i
l
l
void diagonalE|ements(int "'a,In
f
int i,j,c=0;
for(i=0;i<n;i++)
f
for(j=0;j<n;j++)
(
if(i|=j)
l
1t<<'<'<a+i>+m==<>>
(
C++;
l
l
l
i
"(<===(("")-"ll
l
printf("yes");
}
else
i
printf("no")2
l
l
Sample Input
2
4 5
5 4
Sample Output
FIO
Result
Thus, Program " DIAGON
matrix which has zeros everywhere other than the main diagonal. Entries on the main
diagonal may be any
a program to find whether a given matrix is a diagonal matrix or not. Input Format:
The input consists of
integer corresponds to the number of rows/columns in the matrix. The remaining
integers correspond to the
e elements are read in row wise order, first row first, then second row and so on.
Assume that the maximum
put Format: Print yes if it is a diagonal matrix. Print no if it is not a diagonal
matrix.
tn)
AL MATRIX" has been successfully executed

Course: C Srbject Code:


Q. UNIFORMITY MATRIX using Function
Uniformity matrix is a matrix in which all the elements in the matn'x are either
completely even or completely odd
Source Code
#lnclude<stdIo.h>
#lnclude<stdl|b.h>
Int "createArray(int);
void getElements(int",int);
void uniformityDlagona|s(int",Int)1
Int maIn()
l
Int "a,n;
scanf("%d",&n);
a=createArray(n);
getElements(a,n);
uniformityDiagonaIs(a.n);
retum 0:
l
Int "'createArray(int n)
l
Int "a,i;
a=(Int)malloc(n'sizeot(int'))1
for(l=0;i<n;l++)
(
'(a+l)=(int')mal|oc(nsizeoi(int));
l
retum a;
l
void getE|ements(int "a,lnt n)
l
int I,j;
for(l=0;i<n;l++)
l
for(j=0:j<n;j++)
l
scanf("%d",('(a+i)+]));
l
l
l
void uniformityDiagonals(int a,int n)
(
um l,j,b=0.c=0,d,e;
for(i=0;i<n;i++)
l
d=0:
for(j=0;j<n;j++)
(
"(i==i)
(
<1=(('(a+i)+l));
li((d==e)&&(dl=0))
(
printf("no");
retum;
l
l
l
e=d;
l
for(i=0;i<n;l++)
(
for(j=0;j<n;j++)
(
1m<'<'(a+I>+1>>%2==<>>>
(
C++;
l
else
(
b++;
l
// printf("%d\n",e);
l
l
"(==("'"l||b==(""))
l
printt("yes");
l
else
l
printt("no");
l
l
Sample Input
45
54
Sample Output
no
Result
Thus, Program " UNIFORMITY MATRIX using Function" has been successfully executed

Course: C Spbject Code:


Q. MAGIC SQUARE
A magic square is an arrangement of numbers (usually integers) in a square grid,
where the numbers in each row, and in each column,
and the numbers in the fonlvard and backward main diagonals, all add up to the same
number. Write a program to find whether a given
matrix is a magic square or not. Input Format: The input consists of (n*n+1)
integers. The first integer corresponds to the number of
rows/columns in the matrix. The remaining integers correspond to the elements in
the matrix. The elements are read in row wise order,
first row first, then second row and so on. Assume that the maximum value of m and
n is 5. Output Format: Print yes if it is a magic
square. Print no if it is not a magic square.
Source Code
#Include<stdio.h>
#lnc|ude<stdl|b.h>
int "createArray(int);
void getE|ements(int",lnt);
void magicSquare(Int",int);
lnt main()
l
int "a,n;
scanf("%d".8-n);
a=createArray(n);
getElements(a,n);
maglcSquare(a,n);
retum 0;
l
lnt "'createArray(int n)
l
lnt "a,l2
a=(Int")ma||oc(nsizeof(int'))I
for(i=0;i<n;l++)
(
'(a+l)=(lnt ')malloc(n'sizeof(lnt'));
l
retum a;
l
void getElements(int "a,lnt n)
l
lnt i,j;
f0r(l=0;i<n;i++)
(
for(j=0;j<n;]++)
(
scanf("/<>d",'(a+I)+j);
l
l
l
void magicSquare(lnt "a,int n)
l
int l,j,sum=0,sum1=0,r=O,c=0,sum2,sum3,sum4,sum5;
sum=0;
for(i=0;i<n;|++)
l
sum=0;
for(j=0;j<n;j++)
(
sum=sum+"('(a+i)+j);
l
sum2=sum;
lf(sum1==sum)
(
r++;
l
sum1=sum;
l
lf(rl=n-1 && suml=0)
l
printf("no")2
retum;
l
printf("\n");
sum1 =0;
for(j=0:j<n;j++)
(
sum=0;
for(i=0;i<n;l++)
(
sum=sum+('('(a+l)+j));
l
lf(sum1==sum)
l
c++;
}
sum1=sum;
l
sum3=sum;
//printf("sum3 %d\n',sum3);
lf(cl=n-1&&suml=0)
l
printf("n0"):
retum;
l
sum1=0;
sum=0;
for(l=0:i<n;l++)
f
for(j=0;j<n;j++)
t
"(i==l)
l
sum=sum+('(a+i)+]);
l
l
l
sum4=sum;
//printf("sum4 />d\n',sum4);
sum=0;
sum1=0;
for(l=0:i<n;l++)
l
for(j=0;j<n;j++)
(
sum=sum+('(a+i)+]);
break;
l
sum1=sum;
l
sum5=sum;
//printf("sum5%d\n",sum5);
lf(sum4==sum5)
(
lf((sum2==sum3)&&(sum3==sum4)&&(sum2==sum4))
l
printf("yes");
l
}
else
l
printf("no");
retum;
}
l
Sample Input
2
4 5
5 4
Sample Output
HO
Result
Thus, Program " MAGIC SQUARE" has been successfully executed

course: C Spbject Code:


Q. Maximum Element in an Array using Functions
Write a program to find the maximum element in an array. lnput Format: lnput
consists of n+1 integers. The first integer corresponds to n
, the size of the array. The next n integers correspond to the elements in the
array. Assume that the maximum value of n is 15. Output
Format: Refer sample output for details.
Source Code
#include<stdio.h>
#inc|ude<stdlib.h>
int main()
i
Int 'a,n,i,max;
scanf("%d".&n)I
a=(int')malloc(nsizeof(lnt));
for(|=0;i<n;l++)
{
scanf("%d",a+i);
}
max=O;
tor=0j<n++)
if(max<'(a+i))
l
ma.x=(a+i);
} printt('/<>d is the maximum element in the array",max);
retum 0;}
Sample Input
5
23681
Sample Output
8 is the maximum element in the array
Result
Thus, Program "Maximum Element in an Array using Functions" has been successfully
executed

Subject Code:
Course: C H
Q. Sum of 2 arrays using Functions
Write a program to find the sum of the corresponding elements in 2 arrays. Input
Format: Input consists of 2n+1 integers. The first
integer corresponds to n , the size of the array. The next n integers correspond to
the elements in the first array. The last n integers
correspond to the elements in the second array. Assume that the maximum value of n
is 15. Output Format: Refer sample output for
details
Source Code
#lnclude<stdlo.h>
#lnclude<stdI|b.h>
Int 'createArray1(lnt);
Int createArray2(lnt):
void readE|ement1(int",int):
void readElement2(int'.int);
void sumofArray(int',int',int);
Int maln()
I
Int 'a,n.'b;
scanf("%d".&n);
a=createArray1 (n);
b=createAn'ay2(n);
readElement1(a.n);
readElement2(b.n);
sumofArray(a,b,n):
//printf("%d,c);
retum 0;
l
Int createArray1(int n)
I
Int a;
a=(Int ')ma|loc(n'sizeof(Int));
retum a;
l
Int 'createArray2(lnt n)
l
Int b;
b=(lnt ")malloc(n'sIze0f(lnt));
retum b;
l
void readElement1 (int 'a,int n)
I
Int I;
for(i=0;i<n;l++)
scanf("%d",a+i);
l
void readEIement2(int 'b,int n)
I
Int i;
for(i=0;i<n;i++)
scanf("%d',b+i);
l
void sumofArray(int a,int 'b,int n)
I
Int l,sum=0;
for(l=0;i<n;l++)
I
sum='(b+i)+(a+i);
plll'l("/od ",sum);
l
l
Sample Input
s
23682
1 1 1 1 1
Sample Output
34793
Result
Thus, Program " Sum of 2 arrays using Functions" has been successfully executed

Subject Code:
Course: C H
Q. Sum of 2 arrays using Functions
Write a program to find the sum of the corresponding elements in 2 arrays. Input
Format: Input consists of 2n+1 integers. The first
integer corresponds to n , the size of the array. The next n integers correspond to
the elements in the first array. The last n integers
correspond to the elements in the second array. Assume that the maximum value of n
is 15. Output Format: Refer sample output for
details
Source Code
#lnclude<stdlo.h>
#lnclude<stdI|b.h>
Int 'createArray1(lnt);
Int createArray2(lnt):
void readE|ement1(int",int):
void readElement2(int'.int);
void sumofArray(int',int',int);
Int maln()
I
Int 'a,n.'b;
scanf("%d".&n);
a=createArray1 (n);
b=createAn'ay2(n);
readElement1(a.n);
readElement2(b.n);
sumofArray(a,b,n):
//printf("%d,c);
retum 0;
l
Int createArray1(int n)
I
Int a;
a=(Int ')ma|loc(n'sizeof(Int));
retum a;
l
Int 'createArray2(lnt n)
l
Int b;
b=(lnt ")malloc(n'sIze0f(lnt));
retum b;
l
void readElement1 (int 'a,int n)
I
Int I;
for(i=0;i<n;l++)
scanf("%d",a+i);
l
void readEIement2(int 'b,int n)
I
Int i;
for(i=0;i<n;i++)
scanf("%d',b+i);
l
void sumofArray(int a,int 'b,int n)
I
Int l,sum=0;
for(l=0;i<n;l++)
I
sum='(b+i)+(a+i);
plll'l("/od ",sum);
l
l
Sample Input
s
23682
1 1 1 1 1
Sample Output
34793
Result
Thus, Program " Sum of 2 arrays using Functions" has been successfully executed

course: C lbject Code:


Q. Searching an Array using Functions
Write a C program to search for an element "a in the array. (Linear Search)
Source Code
#lnclude<std|o.h>
#include<stdl|b.h>
Int 'createArray(int)2
void readElement(lnt ',int);
void Array(int ',int);
Int main()
l
Int 'a,n;
scant("%d".8-n);
a=createArray(n);
readElement(a,n);
Array(a,n);
retum 0;
l
lnt createArray(int n)
l
Int a;
a=(Int ')malloc(n'slzeof(lnt));
retum a;
l
void readElement(int 'a,int n)
(
lnt i;
for(|=0:i<n;l++)
l
scanf("%d,a+i);
l
l
void Array(int 'a.int n)
l
Int b,l,c=0;
//printf("b=');
scanf("%d".&b);
for(i=0;i<n;l++)
l
lf('(a+i)==b)
l
C++;
l
l
lf(c==1)
l
printf("%d is present in the array",b):
l
else
l
printf(%d ls not present in the array".b);
l
l
Sample Input
s
23661
6
Sample Output
6 is present in the array
Result
Thus, Program "Searching an Array using Functions" has been successfully executed

Course: C 11
Subject Code:
Q. No. of Distinct E
Write a program to f
of n+1 integers. The
in the array. Assume
number of distinct el
Source Code
#include<stdio.h>
#lnclude<stdl|b.h>
int 'createArray(int);
void readE|ement(lnt ',int
void distinctElement(int
int main()
t
lnt 'a,n;
scanf("%d".&n)3
a=createArray(n);
readE|ement(a,n);
dlstlnctE|ement(a,n);
retum O;
l
lnt 'createArray(int n)
l
Int a;
a=(lnt ')malloc(n'slzeof(|n
retum a;
l
void readElement(int 'a,'
In
(
Int I;
for(i=0;i<n;i++)
t
scanf("%d".a+i);
l
l
void distinctElement(int
a
l
lnt l.j,b=1,d=0:
for(i=0;i<n;l++)
(
d++;
for(j=i+1;]<n:j++)
(
ll('(a+i)=='(a+j)&&b==1)
t
d--.
b=0:
l
l
b=1 1
l
printf("%d",d);
l
Sample Input
7
3452334455
Sample Output
7
Result
Thus, Program " No.
Iements in an unsorted array
ind the number of distinct elements in a unsorted array. [Do it without sorting the
array] Input Format: Input consists
first integer corresponds to n, the number of elements in the array. The next n
integers correspond to the elements
that the maximum value of n is 15. Output Format: Output consists of a single
integer which corresponds to the
ements in the array.
)2
rm);
1));
tn)
.int n)
of Distinct Elements in an unsorted array" has been successfully executed

Course: C Srbject Code:


Q. Matrix Sum using Function
Write a program to find the sum of the elements in the matrix. Input Format: The
input consists of (m*n+2) integers. The first integer
corresponds to m, the number of rows in the matrix and the second integer
corresponds to n, the number of columns in the matrix. The
remaining integers correspond to the elements in the matrix. The elements are read
in row-wise order, first row first, then second row
and so on. Assume that the maximum value of m and n is 10. Output Format: Refer
sample output for details.
Source Code
#lnclude<stdlo.h>
#lnclude<stdl|b.h>
lnt "createArray(int,Int);
void getElements(int",int,int);
int sumofArrays(int"'.int,int);
lnt maln()
(
lnt "a,rows,columns,sum;
scanf("%d",&rows);
scanf("%d',&columns);
a=createArray(rows,co|umns);
getElements(a,rows,columns);
sum=sumotArrays(a,rows,columns);
printt("The sum of the elements in the matnx is %d",sum);
retum 0;
i
Int "createArray(int rows,int columns)
l
lnt "a,IZ
a=(Int")malloc(rows'slzeot(int'))3
for(i=0;i<rows;i++)
i
'(a+l)=(int ')mal|oc(columnssizeot(lnt));
l
retum a;
l
void getElements(int "a,lnt rows,int columns)
(
int |,j;
for(l=0;i<rows;l++)
{
tor(j=0;j<columns;j++)
(
scant("%d'.('(a+i)+]));
)
l
l
lnt sumotArrays(int "a,int rows,lnt columns)
i
lnt i,j,sum=0;
for(i=0;i<rows;l++)
(
for(j=0;j<columns;]++)
l
sum=sum+('('(a+i)+j));
l
l
retum sum;
l
Sample Input
3 2 4 5 6 9 0 3
2
4 5
6 9
0 3
Sample Output
The sum of the elements in the matrix is 27
Result
Thus, Program " Matrix Sum using Function " has been successfully executed

Course: C 11
Subject Code:
Q. F
Write a
array
som
m
ele
corr
Sou
#lncl
#lncl
int C
void
int
lnt m
508
8=C|'
prin
l
retu
l
int 'c
(
a=(ln
retu
i
void
lnt I;
//prin
for(|=
f
sca
l
l
int
l
int i.
//prin
|f('(a
l
c++;
l
else
(
b++
1r( =
|'9tU
i
8|$6
l
YGIU
l
el
l
f U
l
retu
l
Sa
5
2 4 1
Sa
The
Res
Thu
ndTy
ain(
getEl
c=fin
I =
p|'lIt
else I
pnn
else I
Int a;
m
l
nf
ndf
c0
i
8|S6
l
d++;
i
l
C
(
m
m
se
et m
m
m
ITI
9
array is
Mixed.
integer
element
P
GS
PC
ude
ude
reat
get
(II
(
int 'a.
pnn
nf
f(c =1)
(
. m
) .
(
r
l
l
r
m
f(c
f(c
0
t")
3
get
tr("
"(
+i)
for(l=0;i<n;l++)
(
/2
m*<
=n)
1
mu
2
3
0
P
P
arra
5
UH
6S
("%
eate
em
dTy
re at
0;i<
("%
I
as
I
ctions-Array Type
program to find the type of the array using functions. An array is said to be ?
Even? if all the elements in the array are even. An
ome even elements Refer function specifications for the function details The first
argument corresponds to the number of
s in the array. The second argument corresponds to the pointer to an array. The
return value of the function should be 1 if the
Even. The return value of the function should be 2 if the array is Odd. The return
value of the function should be 3 if the array is
Input and Output Format: Input consists of n+1 integers where n corresponds to the
number of elements in the array. The first
corresponds to n and the next n integers correspond to the elements in the array.
Assume that the maximum number of
s in the array is 20. Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest
onds to output
is said to be ?Odd? if all the elements in the array are odd. An array is said to
be ?Mixed? if it contains some odd elements and
nt
e Code
<StdlO.h>
<std||b.h>
eArray(int);
Element(int,int );
pe(int,int );
)
TLC;
Enter the number of elements in the array\n");
d".&n);
Array(n);
ent(n,a);
P6018);
"The array is Even");
==2)
"The array is Odd");
==3)
"The array is Mixed");
eArray(int n)
ma|loc(n'slzeof(lnt));
E|ement(int n,int 'a)
Enter the elements in the array\n");
n;l++)
d",a+i);
ype(int n,int 'a)
.b=0,d=0;
a=%d",(a+i));
2==0)
a+i)/O2==1)
e Input
e Output
y is Mixed
ult
Program " Functions-Array Type" has been successfully executed
Course: C Srbject Code:
Q. Compare 2 arrays using Function
Write a program to find whether 2 arrays are the same. Input Format: Input consists
of 2n+1 integers. The first integer corresponds to ?
n? , the size of the array. The next ?n? integers correspond to the elements in
the first array. The next ?n? integers correspond to the
elements in the second array.Assume that the maximum value of n is 15. Output
Format: Print yes if the 2 arrays are the same. Print no
if the 2 arrays are different.
Source Code
#lnclude<stdlo.h>
#lnclude<stdl|b.h>
int 'createArray(int);
void getElement1 (int ',int);
void getE|ement2(int ',int);
void checkArray(int ',int ,int);
int main()
t
int 'a,b.n;
scanf("%d".&n)2
a=createArray(n);
b=createAn'ay(n);
getE|ement1(a_n);
getElement2(b,n);
checkArray(a,b_n);
retum O;
l
int "createArray(int n)
(
int a;
a=(int ')mal|oc(n'sizeof(Int));
retum a;
l
VOid getE|ement1(int 'a,int n)
t
int I;
for(l=0;i<n;l++)
(
scanf("%d",a+i);
l
l
void getE|ement2(int 'b,int n)
(
int ii
for(i=0;i<n;i++)
(
scanf("%d',b+i);
l
l
void checkArray(int a,int b.int n)
(
int i,c=0;
for(|=0:i<n;l++)
l
//printf("a+i=%d\n".'(a+i));
//printf("b+i=%d\n"."(b+i));
"(((8+i))==((b+i)))
i
c++;
l
l
lf(c==n)
t
printf("yes");
l
GISG
t
printf("no")2
l
l
Sample Input
s
23634
23684
Sample Output
YES
Result
Thus, Program " Compare 2 arrays using Function" has been successfully executed

course: C Spbject Code:


Q. No. of Distinct Elements in an unsorted array
Write a program to find the number of distinct elements in a unsorted array. [Do it
without sorting the array] Input Format: Input consists
of n+1 integers. The first integer conesponds to n, the number of elements in the
array. The next n integers correspond to the elements
in the array. Assume that the maximum value of n is 15. Output Format: Output
consists of a single integer which corresponds to the
number of distinct elements in the array.
Source Code
#lnclude<stdlo.h>
#inc|ude<stdllb.h>
lnt createArray(int);
void readElement(lnt ',int);
void distinctElement(int *,int);
int main()
l
int 'a,n;
scanf("%d".8-n);
a=createArray(n):
readElement(a,n);
dlstlnctElement(a,n);
retum 0;
l
int "createArray(int n)
l
lnt a;
a=(lnt ')malloc(n'slzeof(lnt));
retum a;
l
void readElement(lnt 'a,int n)
(
int i;
f0r(i=0li<n;l++)
l
scanf("%d',a+i);
i
l
void distinctElement(int a.int n)
l
lnt i.j.b=1_d=0:
for(|=0:i<n;l++)
l
d++;
for(j=i+1;]<n;j++)
l
"('(a+i)=='(3+j)&&b==1)
(
d~-;
b=0:
l
l
b=1 ;
l
printf("%d",d);
l
Sample Input
7
3452334455
Sample Output
7
Result
Thus, Program " No. of Distinct Elements in an unsorted array" has been
successfully executed

Q. Sum of pos
Write a progra
Source Code
#include<stdio.h>
#|nclude<std||b.h>
Int 'createArray(in
t
void getE|ement(in
Int sumofArray(int
Int main()
(
int "a,b.n;
scanf("/<>d".&n)2
a=createArray(n);
getE|ement(a,n);
b=sumofArray(a,n
printf("The sum of
retum 0:
l
Int 'createArray(in
l
int a;
a=(lnt )mal|oc(nsl
retum a;
}
void getE|ement(in
(
Int I.
for(i=0;i<n;i++)
l
scanf("%d",a+i);
l
l
int sumofArray(int
i
lnt sum=O,i;
for(|=0;i<n;l++)
(
lt('(a+i)>=0)
i
sum=sum+"(a+l);
l
l
retum sum;}
Sample Input
5
2368-1
Sample Outpu
The sum of the po
Result
Thus, Program
Course: C Subject Code
m
itive numbers using Functions
to find the sum of positive numbers in an array.
);
t',int);
int);
);
the positive numbers in the array is %d",b);
tn)
zeof(int));
t 'a,int n)
'8,|I'll I1)
I
sitive numbers in the array is 19
" Sum of positive numbers using Functions" has been successfully executed

Subject Code:
Q. Sum of eve
Write a progra
to ?n? , the siz
Output Format
Source Code
#include<stdio.h>
#lnclude<std||b.h>
Int 'createArray(int
void getE|ement(in
lnt sumofArray(int
int main()
l
int 'a,b.nI
scanf("%d".&n)I
a=createArray(n);
getE|ement(a,n);
b=sumofArray(a,n
printf(The sum of
retum 0;
)
l
int createArray(in
l
int a;
a=(lnt )mal|oc(nsl
retum a;
l
void getE|ement(in
t
lnt I.
for(i=0;i<n;l++)
t
scanf("%d",a+i):
l
}
Int sumofArray(lnt
l
Int sum=O,i;
for(l=0;i<n;l++)
l
if('(a+i)%2==O)
l
sum=sum+'(a+i);
l
l
retum sumz}
Sample Input
5
2368-1
Sample Outpu
The sum of the ev
Result
Thus, Program
Course: C 11
m
n numbers using Functions
to find the sum of even numbers in an array. Input Format: Input consists of n+1
integers. The first integer corresponds
e of the array. The next ?n? integers correspond to the elements in the array.
Assume that the maximum value of n is 15.
Refer sample output for details.
);
t',int);
Int);
the even numbers in the array is %d",b);
t n)
zeof(Int));
t
t 'a,int n)
'a,|nt n)
en numbers In the array is 16
" Sum of even numbers using Functions" has been successfully executed
Q. Sum of eve
Write a progra
Source Code
#|nclude<stdlo.h>
#include<stdl|b.h>
lnt "createArray(in
t
void getElement(in
void sumofArray(ln
rm main()
t
int 'a,n;
scant("%d".&n);
a=createArray(n);
getElement(a,n);
sumofArray(a,n)3
retum 0;
l
lnt 'createArray(in
t
int a;
a=(lnt ')malIoc(n'sl
retum a;
l
void getE|ement(in
(
int i;
for(|=0;i<n;l++)
l
scanf("/<>d",a+i):
l
l
nt
void sumofArray(i
(
int i,sum1=0,sum2
for(l=0;i<n;l++)
(
lf((a+i)%2==0)
(
sum1=sum1+'(a+i
l
else
l
sum2=sum2+'(a+i
l
l
printt("The sum of
printt("The sum of
l
Sample Input
5
2368-1
Sample Outpu
The sum of the ev
The sum of the od
Result
Thus, Program
course: C fubject Code
m
t n
n and odd numbers
to find the sum of even and odd numbers in an array.
):
t',int);
t,lnt);
)
zeot(lnt));
t 'a,int n)
'a,int n)
=0;
)2
)3
the even numbers in the array is /<>d\n".sum1);
the odd numbers In the array ls %d.sum2):
t
en numbers in the array is 16
d numbers in the array ls 2
" Sum of even and odd numbers" has been successfully executed

course: C Spbject Code:


Q. Structurel4
Write a program that uses a structure called date that has it passed to an
isLeapYear function to detennine if the year is a leap year
Input and Output Format: Example: O5/O6/1978 Refer sample input and output for
formatting specification. All float values are displayed
correct to 2 decimal places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#lnclude <stdio.h>
struct date
( int day:
Int month;
lnt year;
);
int lsLeapYear(struct date d):
lnt ma|n()
( struct date d;
//printf("Enter the date (eg: 05/06/1978): ");
SC3l'1f("/od//od//0d", &d.day, &d.month, &d.year);
if (lsLeapYear(d) == 0)
printf("\n %d is not a leap year", d.year);
else
printf("\n %d is a leap year, d.year):
return 0;
l
Int lsLeapYear(struct date d)
(if ((d.year % 4 == 0 && d.year /<> 100 l= 0) |[ d.year % 400 == 0)
retum 1;
else
retum O;
)
Sample Input
osroe/1978
Sample Output
1978 ls not a leap year
Result
Thus, Program " Structurel4 " has been successfully executed

course: C Spbject Code:


Q. Structure -17
Define a structure date containing three integers -day,months and year. Write a
program using functions to read data, to validate the
data entered by the user and then print the date on the screen. For example,if you
enter 31/6/2007 is invalid as June does not has 31
days, similarly if you enter 25/13/2000 then it is invalid month as month ends with
12(1-12. jan to dec). The threshold value for year is
3000 (Invalid Year). Valid year: 0000-2999 Using the structure definition of the
above program, write a function to increment that .Make
sure that the incremented date is a valid date. Modify the above program to add a
specific number of days to the given date.Write a
function to compare two date variable.
Source Code
#lnclude<stdio.h>
struct date
I
Int day;
Int month;
int year;
I;
int enter_date(struct date d);
Int check_vaIldlty(int dd, int mm. int yy);
Int increment_date(struct date d):
Int max_days[12] = {31,28,31,30,31,30,31,31,30,31,30,31);
int maIn()
l
struct date d;
enter_date (d);
I
Int enter_date(struct date d)
( int dd.mm,yy,fIag=O:
//printf("\n Enter the date : ');
SC8I'If("/od//od//od, &dd,&mm.&yy);
flag = check__vaIIdity(dd,mm,yy);
)
(d.day = dd;d.month=mm;d.year=yy;
printf("\n %d-%d-%d", d.day, d.month,d.year):
Increment_date(d);
retum 0:
I
I
Int check_valldIty(int dd. int mm, int yy)
f
lf(yy>2012)
I
printf("\n Invalid Year);
retum O:
I
if(mm<1 I) mm>12)
I
printf("\n Invalid Month");
retum 0;
I
lf(mmI=2 as. (dd<0 1| dd>max_days[mm-1]))
I
printf(\n Invalid Day");
retum 0;
I
if(mm==2)
I
If((yy%4 == 0 8.& yy%100 !=0) || (yy/@400 == 0))
max_days[1] = 29:
else
max_days[1] = 28;
if(dd<0 1| dd>ma.x_days[I])
I
printf('"\n Invalid Date);
retum 0;
I
I
retum 1;
I
Int increment_date(struct date d)
I
d.day++:
if(d.day>max_days[d.month-1])
(d.day = 1;
d.month++Z
lf(d.month>12)
(d.month = 1;
d.year++;
I
I
printf("\nNew Date=%d-%d-%d", d.day, d.month,d.year);
I
Sample Input
31/13/1989
Sample Output
Invalid Month
Result
Thus, Program " Structure -17 " has been successfully executed

course: C Spbject Code:


Q. Structures - 21
Write a program to define a union and structure both having exactly the same
members. Using the sizeof operator, print the size of
structure variable a well as union variable and comment on the result. Tip: Declare
structure with three integer data members and union
with same with integers data members. lnput and Output Format: Refer sample input
and output for formatting specification. All oat
values are displayed correct to 2 decimal places. All text in bold corresponds to
input and the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
struct date
( int day:
int month;
int year;
l;
union DOB
( Int day;
lnt month;
lnt year;
);
Int main()
l
struct date d1;
//long unsigned int d1.d2;
union DOB d2;
Int CZ
scanf("%d",&c);
if(C==1 )1
l
priritf("Size of structure = />ld\n', slzeof(d1));
printf("Size of union = %|d", sizeof(d2));
l
retum 0:
l
Sample Input
1
Sample Output
Size of structure = 12
Size of union = 4
Result
Thus, Program "Structures - 21 " has been successfully executed

Course: C Spbject Code:


Q. Structures - 23
Declare a structure POINT. Input the co-ordinates of a point variable and determine
the quadrant in which it lies. The following table can
be used to determine the quadrant Quadrant X Y 1 Positive Positive 2 Negative
Positive 3 Negative Negative 4 Positive Negative lnput
and Output Format: Refer sample input and output for formatting specification. All
float values are displayed correct to 2 decimal places.
All text in bold corresponds to input and the rest corresponds to output
Source Code
#lnclude<stdlo.h>
typedef struct
l
Int num;
int deno;
}Fract;
Fract sum(Fract,Fract);
int maln()
{
lnt num1,deno1,num2,deno2;
//printf("Enter fraction 1 : numerator denominatorz);
scanf("%d/<>d",&num1 ,&deno1);
//printf("Enter fraction 2:numerator den0mlnator:);
scanf("%d%d",&num2,&deno2);
Fract f1={num1, deno1};// fraction 1
Fract f2 ={num2_. deno2};//fraction 2
Fract result = sum(f1, f2)://sum the fractions
printf("Resu|t=%d//ad",result.num,resu|t.deno); //display the result
retum 0;
1
Fract sum(Fractf1, Fract f2)
{
Fract result={(f1.num ' f2.deno) + (f2.num f1.deno), f1.deno ' f2.deno};
retum result;
}
Sample Input
85
65
Sample Output
Result=70/25
Result
Thus, Program "Structures - 23 " has been successfully executed

course: C Spbject Code:


Q. Structures - 39
write a program to read and display the information of all the students in the
class. THen edit the details of i the student and redisplay
the entire information Input and Output Format: Refer sample input and output for
formatting specification. All oat values are displayed
correct to 2 decimal places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#include<stdio.h>
#include<strlng.h>
int main()
(
struct student
l
int r_no;
char name[20];
char DOB[20];
Int fees;
)2
struct student stud[5O];
int i.n.rolno,new_rolno;
char new_DOb[80],new_name[80];
//prlntf(Enter the number of students:');
scanf('%d,&n);
for(i=0;i<n:i++)
{
//prlntf("\n Enter the data for the student %d:",i+1);
//prlntf("\n Enter the Roll no:");
scanf("%d",&stud[i].r_no);
//pr|ntf("\n Name:");
scant("/<>s".stud[I].name):
//prlntf("\n Course:");
scanf("%s"_stud[l].DOB);
Ii printf("\n Feesz");
scanf("%d",&stud[i].fees);
l
for(i=0;i<n:l++)
{
prlntf("Roll no:/>d\n",stud[i].r_no);
printt(Name:%s\n",stud[i].name);
printf(DOB:%s\n",stud[l].DOB):
printf(Fees:%d\n",stud].fees)I
}
retum 0;
l
Sample Input
2
1101 Ramesh 25dec1990 15000
1102 Suresh 09sep1989 30000
Sample Output
Roll no :1 1 01
Name:Ramesh
DOB:25dec1990
Fees:1 5000
Roll no:1 102
Name:Suresh
DOB:09sep1989
Fees:30000
Result
Thus, Program " Structures - 39 " has been successfully executed

course: C Srbject Code:


Q. Structure - 43
Write a program using a pointer to a structure to initialise the members of the
structure by initialise the values of members in the
program itself and display the values lnput and Output Format: Refer sample input
and output for formatting specification. All float values
are displayed correct to 2 decimal places. All text in bold corresponds to input
and the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
#include<malloc.h>
struct student
l
int r_no;
char name[2O];
char course[20]:
lnt fees;
)2
struct student 'ptr;
lnt maln()
f
int i,n;
struct student stud1={01,"Raj","PHD".50000}:
ptr=&stud1 ;
printf("Detal|s of the student");
printf('"lnRoll no:%d",ptr->r_no);
prlntf('"\nName:/<>s".ptr->name);
prlntf("\nCourse:%s",ptr->course);
printf("\nFees:%d,ptr->fees);
retum 0:
l
Sample Input
0
Sample Output
Details of the student
Roll no:1
Name:Raj
Course:PHD
Fees:50000
Result
Thus, Program " Structure - 43" has been successfully executed

course: C Srbject Code:


Q. Structures - 44
Write a program using an array of pointers to a structure to read and display the
data of a student. Input and Output Format: Refer
sample input and output for formatting specification. All oat values are displayed
correct to 2 decimal places. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
#lnclude<malloc.h>
struct student
l
int r_no;
char name[20];
char course[20];
int fees;
};
struct student "ptr[10];
Int maln()
l
int l,n;
//prlntf("Enter the number of students:");
scanf("%d",&n);
for(i=0;I<nZl++)
{
ptr[l] =(struct student ')malloc(slzeof (struct studentl);
/iprlntf("\n Enter the data for the student %d:",i+1);
// printf('\n Roll not");
scanf("%d",&ptr[i]->r_no);
// prlnlf("\n Namez");
scanf("%s".ptr[i]->name):
ll prlntf("\.n Course:");
scanf("%s".pfr[i]->course);
// prlntf("\n Fees:");
scanf("%d",&ptr[l]->fees);
l
prlntf("Details of the student");
for(i=0;kn;l++)
{
prlntf("\nRoll no:/>d",ptr[i]->r_no);
prlntf(\nName:%s",ptr[q->name);
printf("\nCourse:%s",ptr[l]->course);
printf("\nFees:%d',ptr[i]->fees)1
l
retum O:
l
Sample Input
1 101 ramesh btech 100000
Sample Output
Details of the student
Roll no:101
Namezramesh
Course:btech
Fees:100000
Result
Thus, Program "Structures - 44 " has been successfully executed

Course: C Srbject Code:


Q. Structure 46
Write a program that passes a pointer to a structure to a function which displays
student fee course and fee details lnput and Output
Format: Refer sample input and output for formatting specification. All float
values are displayed correct to 2 decimal places. All text in
bold corresponds to input and the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
#lnclude<malloc.h>
#include<string.h>
struct student
l
lnt r_no;
char name[20];
char course[20]:
lnt fees;
l;
lnt display(struct student ');
Int main()
l
stmct student ptr;
ptr=(struct student )ma|loc(sizeot (struct student));
It prlntf("\n Enter the data for the student");
If prlntf('\n Roll nor);
scanf("%d",&ptr->r_no);
I./prlntf("\n Namez");
scant("/>s",ptr->name);
//prlntf('\n Course);
scanf("%s",ptr->course)I
// printf('\n Fees);
scanf("%d",&ptr->fees);
dlsplaylptr);
return 0;
l
lnt display(struct student 'ptr)
(
printf("\nDetalls of student");
prlntf("\nR0ll Number=%d",ptr->r_no);
printf("\nName=%s",ptr->name)1
printt("\nCourse=%s".ptr->course);
pr1'ntf("\n Fees=%d",ptr->tees);
l
Sample Input
11001 John Phd 115000
Sample Output
Details of student
Roll Number=11001
Name=John
Course=Phd
Fees=115000
Result
Thus, Program "Structure 46 " has been successfully executed
course: C Spbject Code:
Q. Structure 33
Declare a structure fraction that has two fields numerator and denominator .Create
two variables and and compare them using function.
Return 0 it the two variable are equal ,-1 if the fraction is less than the second
and 1 otherwise. You may convert a fraction into a floating
point number for your convenience input and Output Format: Refer sample input and
output for formatting specification. All oat values
are displayed correct to 2 decimal places. Ail text in bold corresponds to input
and the rest corresponds to output.
Source Code
#lnclude<stdio.h>
struct Fraction
( int num;
Int deno;
l;
int get_Fractlon(struct Fraction 'f)
(//printt("\n Enter the numerator and the denominator : ");
scanf("%d %d", &f->num. &f->deno);
return 0;
l
int compare(struct Fraction f1, struct Fraction f2)
(tloat a,b;
a = (oat)(f1->num)/(ft->deno);
b = (oat)(f2->num)r(f2->deno);
"(a'b ==
printt("\n %d I %d is equal to %d I f1->num_. t1->deno_.
f2->num, f2->den0)I
else it (a-b > 0)
printf("\n%d/%d is greater than /od//od". f1 ->num, ti ->deno, f2->num, t2-
>den0):
else
printt("\n/<>d,'%d is smaller than %d/%d". f1->num, f1->deno. f2->num, t2->deno);
retum O:
l
int maln()
( struct Fraction f1,f2I
get_Fraction(&t1):
get_Fraction(&f2);
compare(&t1 .&t2);
retum 0;
l
Sample Input
1212
1222
Sample Output
12/12 is greater than 12/22
Result
Thus, Program " Structure 33 " has been successfully executed

Subject Code:
Course: C H
Q. Structure 42
Write a program , using a pointer to a structure to initialize the members of the
structure to display the students course registration
details where details of first student initialized in the program and details of
second student get from the user , then display the details of
both student 1 and student 2 Input and Output Format: Refer sample input and output
for formatting specification. All float values are
displayed correct to 2 decimal places. All text in bold corresponds to input and
the rest corresponds to output.
Source Code
#lnclude<stdlo.h>
#lnclude<string.h>
#include<malloc.h>
struct student
i
lnt r_no;
char name[20];
char course[20];
int fees;
}:
int main()
l
struct student stud1,stud2,ptr__studt ,ptr_stud2;
ptr_stud1 =&stud1 ;
ptr_stud2=&stud2:
ptr_stud1 ->r_no=O1 I
strcpy(ptr_stud1 ->name,"Ra]");
strcpy(ptr__stud1->course,"PHD");
ptr_stud1->fees=14000;
//printt("Enter the details of the second student");
/1 prlntf("\n Enter the Roll no:");
scanf("%d",&ptr_stud2->r_no);
1/ prlntf("\n Enter the Namez");
scanf("%s",ptr_stud2->name);
//prlntf("\n Enter the Courset);
scant("%s".ptr_stud2->course);
1/ pr|ntf("\n Enter the Feesi);
scanf("/<>d"_&ptr_stud2->tees);
// printf("Detal|s of the Flrst student");
prlntf('\nRo|l l'tOZ/od", ptr_stud1->r_no);
prlntf("\nName:%s". ptr_stud1->name);
printt("\nCourse:%s", ptr_stud1->course);
prlntf("\nFees:/>d, ptr_stud1 ->fees);
// printf("Details of the Second student");
prIntf("\nRo|l no:%d", ptr_stud2->r_no);
prlntt("\nName:%s", ptr_stud2~>name);
prlntt("\nCourse:%s", ptr_stud2->course):
prlntt("\nFees:%d", ptr_stud2->tees);
retum 0;
l
Sample Input
12 ram lt 2333
Sample Output
Roll no:1
Name:Ra]
Course:PHD
Fees :1 4000
Roll no: 1 2
Namezram
Courseilt
Fees:2333
Result
Thus, Program " Structure 42 " has been successfully executed
course: C Spbject Code:
Q. Pointer 26
Write a program to compare two arrays using pointers. Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude<stdlo.h>
int maln()
(int arr1[10], arr2[1O], i=0, n1, n2, equal = 1;
//printf("\nEnter the number of elements in the first array:");
SC8f("kd'. &n1 )1
//printf("\nEnter the elements of the first array:");
for(l=0;i<n1;i++)
scant("%d". (arr1+i));
//printf("\nEnter the number of elements in the second array:");
scanf("%d". &n2)2
//printf("\nEnter the elements of the second array:");
fOl(i=0;i<n2;l++)
scanf("/ed. (arr2+i));
==n2)
( for(l=0;i<n1;l++)
( if('(arr1+i) l= (arr2+i))
( equal = O;
break;
l
l
l
ll(equa|==O || n1l=n2)
printf("\nArrays are not equal");
else
printf("\nArrays are equal):
retum 0:
l
Sample Input
5
12345
5
12345
Sample Output
Arrays are equal
Result
Thus, Program " Pointer 26 " has been successfully executed

Course: C Spbject Code:


Q. Pointer 1
Write a program to print "Hello World" using pointers Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#include<stdio.h>
Int maIn()
l
char s[]="He||o Wor|d";
char 'p;
P=5
wh||e('pl='\0)
{
printf("/<>c".'p);
p++;
}
return 0:
l
Sample Input
0
Sample Output
Hello World
Result
Thus, Program " Pointer 1 " has been successfully executed

course: C Spbject Code:


Q. Pointer 3
Write a program to subtract two double values using pointer Input and Output
Format: Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output
Source Code
#include<stdio.h>
int main()
l
double d1 =0.d2=0.sub,'p1 ,'p2:
//prlntf("\nEnter 1st number: "):
scanf("/<>|f",&d1);
//printf('\nEnter 2nd number: ");
scanf('%|f",&d2);
p1 =&d1;
p2=&d2;
sub='p1-p2;
printf("\n Difference of %lf and /off is /<>|f",'p1.'p2.sub);
return 0;
}
Sample Input
4
5
Sample Output
Difference of 4.000000 and 5.000000 is -1.000000
Result
Thus, Program " Pointer 3 " has been successfully executed

course: C Spbject Code:


Q. Pointer - 4
Write a program to convert 3.14 into its integral equivalent using pointer Input
and Output Format: Refer sample input and output for
formatting specification. All float values are displayed correct to 2 decimal
places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#include<stdlo.h>
int main()
l
float pi=3.14;
float 'd:
d=&pi:
int a='d:
printf("%d",a);
return 0:
l
Sample Input
3.14
Sample Output
3
Result
Thus, Program " Pointer - 4 " has been successfully executed

Course: C Spbject Code:


Q. Pointers 5
Write a program to find smallest of three integer values using pointers Input and
Output Format: Refer sample input and output for
formatting specification. All oat values are displayed correct to 2 decimal
places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#include<stdlo.h>
int main()
(
lnt a,b,c,'al,'b1,'c1;
// prlntf('Enter the three integers");
scanf("%d %d %d,&a,&b,&c);
al=&a;
b1=&b;
c1=&c;
if('al>'b1)
{
if('al>'c1)
printf("%d ls largest\n",'al);
else
prlntf(/ed is largest\n",'b1);
}
else
{
if('b1>'c1)
printf("%d is largest\n",'b1);
else
prlntf("%d is largest\n".'c1);
}
return 0;
l
Sample Input
4
s
1
Sample Output
4 is largest
Result
Thus, Program " Pointers 5 " has been successfully executed

course: C Srbject Code:


Q. Pointers 6
Write a program to input a character and Categorize it as a vowel and consonant
lnput and Output Format: Refer sample input and
output for formatting specification. All oat values are displayed correct to 2
decimal places. All text in bold corresponds to input and the
rest corresponds to output.
Source Code
#include<stdlo.h>
lnt maln()
l
char c,'p;
//prlntt(Enter a alphabet 1 ");
scanf("%c",&c)2
p=&c;
if<'p=='a'||'p=='e'||'p=='i'| |'r>=='<>'|lr>=='u')
printf("The entered alphabet is a vowel");
else
printt("The entered alphabet ls a consonant");
retum 0;
l
Sample Input
8
Sample Output
The entered alphabet ls a vowel
Result
Thus, Program " Pointers 6 " has been successfully executed

course: C Spbject Code:


Q. Pointer - 7
Write a program to input 10 values in an array. Categorize each value as
positive ,negative or equal to zero using pointer. Input and
Output Format: Refer sample input and output for formatting specification. All
float values are displayed correct to 2 decimal places. All
text in bold corresponds to input and the rest corresponds to output.
Source Code
#include<stdlo.h>
int main()
l
Int a[10],p;
1/ prlntf('Enter 10 elements :\n");
lnt i;
for(i=0;k10;i++)
scanf("%d",&a[l]);
P=aI
for(i=0;k10:i++)
{
if('p>O)
printf("\n/>d-Positive",'p);
else if(p<0)
printf("\n%d-Negative",'p):
else
printf("\n%d=Zero",p);
p++;
l
return 0;
l
Sample Input
0
Sample Output
0
Result
Thus, Program " Pointer - 7 " has been successfully executed

course: C Srbject Code:


Q. Pointers 8
Write a program to display the sum and average of number from 100 to 200 using
array declaration with pointers. Input and Output
Format: Refer sample input and output for formatting specification. All oat values
are displayed correct to 2 decimal places. All text in
bold corresponds to input and the rest corresponds to output. sum=xxxxx and
average=xxx.xxxxxx
Source Code
#include<stdlo.h>
lnt main()
i
Int a[100],'p;
P=3l
int sum=0:
int i,s=2;
lt(s==2)
l
for(i=0;i<99:i++)
{
'p=100+i;
p+-H
}
P=3
tor(i=0;i<99;i++)
{
sum=sum+(p);
p++;
l
oat avg=sum/100.0;
printt('sum=%d and average=%t_sum,avg);
return 0;
l
l
Sample Input
0
Sample Output
0
Result
Thus, Program " Pointers 8 " has been successfully executed

Subject Code:
Course: C H
Q. Pointers - 9
Write a program to input 10 values in an array. Categorize each value as prime or
composite using pointers. input and Output Format
Refer sample input and output for formatting specification. All float values are
displayed correct to 2 decimal places. All text in bold
corresponds to input and the rest corresponds to output.
Source Code
#include<stdlo.h>
int main()
(
nt
inta[10].p.i,j.cou =0;;
// printf("\nEnter 10 values into the array: ");
for(i=-O;i<10;i++)
{
scanf("%d",&a[i]);
}
P=a3
for(i=0;i<10:i++)
l
for(j=2:j<'p;j++)
i
lf(('P)%i==0l
{
count++;
l
l
if(count==0)
printf("\n/>d is a prime number",p)2
else
printf("\n%d is a composite number',p);
p++;
count=0;
i
return 0:
l
Sample Input
3456789101112
Sample Output
3 is a prime number
4 is a composite number
5 is a prime number
6 is a composite number
7 is a prime number
8 is a composite number
9 is a composite number
10 ls a composite number
11 ls a prime number
12 ls a composite number
Result
Thus, Program " Pointers - 9 " has been successfully executed

Course: C Spbject Code:


Q. Pointers - 10
Write a program to add two integers using functions use call by address technique
of passing parameters and also illustrate the concept
of pointer variables can be used to access the strings. Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude<stdlo.h>
lnt addllnt ',lnt ' );
lnt main()
t
int a,b,sum;
// prlntf('Enter the value of two numbers:");
scanf("/>d %d ",&a.&b)2
sum=add(&a.8-b):
printf("\nThe sum of the numbers is %d",surn);
printf("\nAccessing a string using polnter");
char c[]="\nHell0";
char p;
P=;
wh|le('pl='\O)
{
prlntf("%c",'p);
p++;
l
printf("\n");
return 0:
l
int add(int 'x. int 'y)
(
int s;
s='x+'y;
return s;
l
Sample Input
6
7
Sample Output
The sum of the numbers is 13
Accessing a string using pointer
Hello
Result
Thus, Program " Pointers - 10 " has been successfully executed

Course: C Spbject Code:


Q. Pointer - 11
Write a program to print "Good Morning" using Pointers. Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#include<stdio.h>
lnt maIn()
{
char s[]="Good Moming':
char 'p;
P=5
wh||e('pl='\0)
{
printf("/<>c".'p);
p++;
}
return 0:
l
Sample Input
0
Sample Output
0
Result
Thus, Program " Pointer - 11 " has been successfully executed

Course: C Srbject Code:


Q. Pointer - 19
Write a function to calculate roots of a quadratic equation . The function must
accept arguments and return result using pointers. Input
and Output Format: Refer sample input and output for formatting specification. All
float values are displayed correct to 2 decimal places
All text in bold corresponds to input and the rest corresponds to output.
Source Code
#include <stdio.h>
#lnc|ude <math.h>
lnt main()
l
double a, b, c. determinant, root1,roo , realPart, ImaginaryPart;
I2
// prlntf('Enter coefficients a,b and c:");
scanf(%|f /elf /o|f".&8, &b, &C);
determinant = bb-4'ac;
// COdltiOl'I TOY real and different F0015
if (determinant > 0)
{
// sqrt() function retums square root
root1 = (-b+sqrt(determlnant))/(2'a);
root2 = (-trsqrt(determinant))/(2'a);
prlntf("\nroot1=%.2lf and r0ot2=%.2lf",root1 ,root2);
l
//condition for real and equal roots
else if (determinant == O)
{
root1 = root2 = -b/(2'a);
printf("\nroot1 =root2=%.2lf;",root1 )1
}
If If roots are not real
else
l
realPart = -b/(2'a);
imaglnaryPart = sqrt(-determinant)/(2"a);
prlntf("\nroot1=%.2lf+%.2| and ro0t2=%.2f-%.2fl". rea|Part. imaginaryPart,
realPart. imaginaryPart);
}
return 0:
l
Sample Input
1
2
5
Sample Output
root1=-1.00+2.00i and root2=-1.00-2.00i
Result
Thus, Program " Pointer - 19 " has been successfully executed

course: C Srbject Code:


Q. Pointer - 20
Write a program using pointers to insert a value in an array. Input and Output
Format: Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#include<stdlo.h>
void lnsert(int arr[], Int 'num, int pos, int 'n)
( int I:
for(i=n;i>='pos;i--)
arr[l+1] = arr[l];
arr['pos] = 'num;
"n++;
l
int main()
(int i. n, num, pos. arr[10];
//printf("\nEnter the number of elements in the arrayf);
scanf("%d". &n);
for(i=0;i<n;i++)
scanf("/ed". &arr[i]);
//printf("\nEnter the number to be insertedf):
scanf("%d". &num);
//printf("\nEnter the position at which the number has to be addedi);
scanf("%d". &pos);
lnsert(arr, &num, &pos, &n);
printf("\nThe array after Insertion of /<>d is:'. num);
for(i=0;i<n+1;i++)
printf("\nArr[%d]=%d",i_arr[i]);
retum 0;
l
Sample Input
3
99 199 299
399
1
Sample Output
The array after insertion of 399 is:
Arr[0]=99
Arr[1]=399
Arr[2]=199
Arr[3]=299
Result
Thus, Program " Pointer - 20 " has been successfully executed

course: C Srbject Code:


Q. Pointers - 21
Write a program using pointers to search a value from an array using pointer Input
and Output Format: Refer sample input and output for
formatting specification. All oat values are displayed correct to 2 decimal
places. All text in bold corresponds to input and the rest
corresponds to output.
Source Code
#|nclude<stdlo.h>
int main()
( int arr[10], num. i. n, found = 0, pos = -1:
lnt pnum=&num;
//printf("\nEnter the number of elements in the array:"):
scanf("%d". &n);
//printf("\nEnter the elementsz");
for(l=0;i<n;l++)
scanf("%d", (arr+l));
//printf("\nEnter the number that to be searchedz");
scanf("%d". pnum);
for(i=0;i<n;i++)
( if('(arr+i) == pnum)
(found =1 ;
pos=i;
printf("\n%d is found in the array at posItion=%d",pnum, i);
break;
l
l
if (lOUnd ==
printf("\n%d Does not exist in the array. num);
return 0;
l
Sample Input
3
45 67 as
99
Sample Output
99 Does not exist in the array
Result
Thus, Program " Pointers - 21 " has been successfully executed

course: C Spbject Code:


Q. Pointer - 26
Write a program to compare two arrays using pointers. Input and Output Format:
Refer sample input and output for formatting
specification. All float values are displayed correct to 2 decimal places. All text
in bold corresponds to input and the rest corresponds to
output.
Source Code
#lnclude<stdlo.h>
int maln()
(int arr1[10], arr2[1O], i=0, n1, n2, equal = 1;
//printf("\nEnter the number of elements in the first array:");
SC8f("kd'. &n1 )1
//printf("\nEnter the elements of the first array:");
for(l=0;i<n1;l++)
scant("%d". (arr1+i));
//printf("\nEnter the number of elements in the second array:");
scanf("%d". &n2)2
//printf("\nEnter the elements of the second array:");
fOl(i=0;i<n2;l++)
scanf("/ed. (arr2+i));
==n2)
( for(l=0;i<n1;l++)
( if('(arr1+i) l= (arr2+i))
( equal = O;
break;
l
l
l
ll(equa|==O || n1l=n2)
printf("Arrays are not equal");
else
printf("Arrays are equal"):
retum 0:
l
Sample Input
5
12345
5
54321
Sample Output
Arrays are not equal
Result
Thus, Program " Pointer - 26 " has been successfully executed

Course: C Spbject Code:


Q. Pointers - 30
Write a program which takes an input from the user and then checks whether its a
number or a character . If its a character ,determine
whether it is in upper case or lower case Input and Output Format: Refer sample
input and output for formatting specification. All oat
values are displayed correct to 2 decimal places. All text in bold corresponds to
input and the rest corresponds to output.
Source Code
#include<stdio.h>
int main()
(
char ch, poh;
pch = &ch;
//printf("\nEnter any character:");
scanf("%c", poh);
lf('pch >='A' && 'pch<='Z)
(
printf("Upper case character was entered\n");
printf("Lower C8S9=/0C", poh + 32);
l
|f("pch >='a && pch<='z')
(
printf(L0wer case character was entered\n");
printf("Upper case=%c", poh - 32);
l
retum 0;
l
Sample Input
s
Sample Output
Upper case character was entered
Lower case=s
Result
Thus, Program " Pointers - 30 " has been successfully executed

Course: C Srbject Code:


Q. Store and Retrieve
Store and retrieve elements from an array
Source Code
#lnclude <stdio.h>
1m main()
l
int arr1[25], I,n;
//printf("\nlnput the number of elements to store in the array:");
scanf("%d",&n);
ll printf("\nlnput %d number of elements in the array:",n);
for(i=0:i<n;i++)
l
1/ printf("\nE|ement-%d:,l);
scant("%d",arr1+i);
l
printt("\nThe elements you entered arez");
for(l=O;i<n;i++)
{
prlntf("\nelement-%d:%d".l,'(arr1+i));
l
retum 0:
l
Sample Input
5
10 20 30 50 40
Sample Output
The elements you entered are:
element-0:10
element-1 :20
element-2:30
element-3:50
element-4:40
Result
Thus, Program " Store and Retrieve" has been successfully executed

course: C fubject Code:


Q. Maximum of Two Numbers using Pointers
Find the maximum number between two numbers using pointer
Source Code
#Inciude <stdio.h>
#include <stdIib.h>
Int main()
(
int tno,sno,ptr1=&tno,'ptr2=&sno;
ll printt("\n|nput the first number:"):
SC8flf("/0d", ptr1)I
// printt("\nlnput the second number:");
scanf("/>d", ptr2);
it('ptr1>'ptr2)
{
printf("\n%d is the maximum number.'ptr1);
}
else
{
printf("\n/>d ls the maximum number"."ptr2);
}
retum 0:
i
Sample Input
5 9
Sample Output
9 is the maximum number
Result
Thus, Program "Maximum of Two Numbers using Pointers " has been successfully
executed

Course: C ?;.lbj6Cl Code:


Q. Permutations
Generate permutations of a given
Source Code
#lnclude <stdio.h>
#include <string.h>
void changePosition(char 'ch1, char ch2)
(
char tmp;
tmp = 'ch1;
"ch1 = 'ch2:
'ch2 = tmp;
l
void charPermu(char chi, int stno, int end
l
int I;
it (stno == endno)
printf("\n%s". cht)2
else
l
for (I = stno; i <= endnOZ i++)
{
changePosItion((cht+stno)_ (cht+i));
charPermu(cht. stno+1, endno);
changePosition((cht+stno). (cht+i));
l
l
l
Int main()
(
char str[]="SRM;
int n = strlen(str);
printf("The permutations of the string a
re
charPermu(str, O, n-1);
return 0;
l
Sample Input
0
Sample Output
0
Result
Thus, Program "Permutations" h
stri
ng Note: Declare character array to "SRM" in the program
no)
I");
as been successfully executed

Course: C Spbject Code:


Q. Pointers - 30
Write a program which takes an input from the user and then checks whether its a
number or a character . If its a character ,determine
whether it is in upper case or lower case Input and Output Format: Refer sample
input and output for formatting specification. All oat
values are displayed correct to 2 decimal places. All text in bold corresponds to
input and the rest corresponds to output.
Source Code
#include<stdio.h>
int main()
(
char ch, poh;
pch = &ch;
//printf("\nEnter any character:");
scanf("%c", poh);
lf('pch >='A' && 'pch<='Z)
(
printf("Upper case character was entered\n");
printf("Lower C8S9=/0C", poh + 32);
l
|f("pch >='a && pch<='z')
(
printf(L0wer case character was entered\n");
printf("Upper case=%c", poh - 32);
l
retum 0;
l
Sample Input
s
Sample Output
Upper case character was entered
Lower case=s
Result
Thus, Program " Pointers - 30 " has been successfully executed

Course: C lbiect
Code:
Write a program to
for formatting speci
tput. Refer sample input and output for formatting specification. All float values
are displayed correct to 2 decimal
corresponds to ou
places. All text in
Source Code
#include<stdlo.h>
int main()
l
int arr[] = {1,2,3.~4,5.~6
int I, num, 'pnum = &n
for(i=0;i<10;i++)
i
num = '(arr+i);
if('pnum>0)
printf("%d is posltive\n'
else
t
if('pnum<0)
printf("/>d is negative\n",
else
printf("/od is equal to z
i
i
retum 0;
i
Sample Input
Ob@\|,U'l_[0J|\J*
Sample Output
1 is positive
2 is positive
3 is positive
-4 is negative
5 is positive
-6 is negative
7 is positive
8 is positive
-9 ls negative
0 is equal to zero
Result
Thus, Program "P
Q. Pointers - 31
bo
test whether a number is positive ,negative or equal to zero Input and Output
Format: Refer sample input and output
fication. All float values are displayed correct to 2 decimal places. All text in
bold corresponds to input and the rest
Id corresponds to input and the rest corresponds to output.
1.8,-9,0);
UITII
', '(&|f+i))I
'(arr+i));
ero\n", '(arr+i));
ointers - 31 " has been successfully executed

You might also like