Elab
Elab
Elab
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 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 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
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
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
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 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
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
(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
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
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
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
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
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
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
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 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
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 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 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
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 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 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
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
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
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 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