MasterProgramming.in - BCA C Programing Assignment 2021
MasterProgramming.in - BCA C Programing Assignment 2021
a)
ABCDEFG
ABC EFG
AB FG
A G
14.
b).
1
12
12 3
12 3 4
c).
*
* *
* * *
d).
1
11
12 1
13 3 1
14 6 4 1
16. Wr ite a pr ogr am to calculate simple inter est.
17. Wr ite a pr ogr am in which y ou declar e var iable of all
data ty pes suppor ted by C language. Get input fr om
user and pr int the value of each var iable with
alignment left, r ight and column width 10. For r eal
number s pr int their values with two digits r ight to the
decimal.
18. Wr ite a pr ogr am to demonstr ate multiplication table
input fr om user till 10.
Flowchar t:-
Star t
Read mar ks
pe pe
Pe Pe 50 r < 6 40 r < 5
r> r> 0& 0&
=6 &p &p
10 0 er er
0 > > =
Display
=
fail
End
#include< stdio.h>
#include< conio.h>
Void main()
{
Int per ;
Clr scr ();
Pr intf(“Enter per centage of student”);
Scanf(“%d”,&per );
If(per > 100)
{
Pr intf(“\n invalid per cent”);
}
else if(per > = 60)
{
Pr intf(“\n fir st division”);
}
else if(per < 60&&per > = 50) {
pr intf(“second division”);
}
else if(per < 50&&per > = 40) {
pr intf(“\m thir d division”);
}
else
{
Pr intf(“\n fail”);
}
getchI();
}
Output:-
BCA C Assignment Solutions- Master Pr ogr amming.in
Q.2 Wr ite a pr ogr am in c to find pr ime number or not.
Ans.
Flowchar t:-
star t
Read n
i= 2
False W
(i hi
< le
n)
{
if Tr ue
(n
%
i If
(
= n%
0 ) i=
Tr ue
F= 1
If false
(f
=
=
1)
Tr ue
Not pr ime Pr ime
number number
end
Algor ithm:-
● Star t
● Read number
● i= 2
● while(i< n)
● if(n%i= = 0 )
● f= 1
● if(f= = 1) then pr int not pr ime
● else pr int pr ime
● end
Code:-
#include< stdio.h>
#include< conio.h>
void main()
{
int n,i,f;
f= 0 ;
pr intf(" Enter a number " );
scanf(" %d" ,&n);
i= 2;
while(i< n)
{
if(n%i= = 0 )
{
f= 1;
br eak;
}
i+ + ;
}
if(f= = 1)
pr intf(" \n not a pr ime number " );
else
pr intf(" \n pr ime number " );
}
Output:-
BCA C Language Assignment Solutions- Master Pr ogr amming.in
Q.3 Wr ite a pr ogr am in c to find the leap y ear .
Ans.
Algor ithm:-
● star t
● y ear
● if(y ear %4= = 0) then leap y ear
● else not leap y ear
● stop
flowchar t:-
star t
Year
If false
4= (y
ea
=
0) r%
Tr ue
Pr int leap y ear Pr int not leap
stop
Code:-
#include< stdio.h>
#include< conio.h>
int main()
{
int y ear ;
clr scr ();
pr intf(" enter the y ear :" );
scanf(" %d" ,&y ear );
r etur n 0;
}
Output:-
star t
Read n
false Tr ue
n>
0
er r o F= 1
stop tr ue
n=
Wr ite fact stop
=1
f= f*n
n= n+ 1
Algor ithm:-
● star t
● r ead n
● if(n> 0) then f= 1
● if(n= = 1) then f= f*n and n= n+ 1
● wr ite fact -stop
● else er r or
● stop
Code:-
#include< stdio.h>
#include< conio.h>
long int facto(int n)
{
if(n= = 1)
{
r etur n 1;
}
else r etur n n*facto(n-1);
}
void main()
{
long int f;
int num;
pr intf(" Enter any number :" );
scanf(" %d" ,&num);
if(num> 0)
{
f= facto(num);
pr intf(" factor ial is %d" ,f);
}
else
{
pr intf(" \n er r or :given number is %d negative" ,num);
}
}
Output:-
BCA C Language Assignment Solutions- Master Pr ogr amming.in
Q. 5 Wr ite a pr ogr am in c to calculate power using r ecur sion.
Ans.
#include< stdio.h>
#include< conio.h>
long int power (int a,int b)
{
Long int s= 1;
Int I;
If(b= = 0)
{
r etur n 0;
}
for (i= 1;i< = b;i+ + )
{
s= s*a;
}
r etur n s;
}
Void main()
{
long int p;
int c,d;
pr intf(“Enter any two number \n”);
scanf(“%d%d”,&c,&d);
p= power (c,d);
pr intf(“\n power is %d”,p);
getch();
}
Output:-
star t
input
nu I
= m f
= b
0 er
%
Yes 2 No
Display even number Display odd number
End
Algor ithm:-
● star t
● input number
● if(number %2= = 0) then it is even number
● else odd number
● end
#include< stdio.h>
#include< conio.h>
Void main()
{
Int n,r ;
Clr scr ();
Pr intf(“Enter a number :”);
Scanf(“%d”,&n);
r = n%2;
if(r = = 0)
{
Pr intf(“Even number ”);
}
else
{
Pr intf(“odd number ”);
}
getch();
}
Output:-
star t
i= 2
No Yes
n
i <=
n3= n1+ n2
n1= n2;
n2= n3, i+ +
Display n3
-
end
Algor ithm:-
● star t
● declar e var iable i,n,n1,n2,n3
● intialize n1= 0,n2= 1and n3= 0
● input number
● i= 2
● check i< = n then n3= n1+ n2,n1= n2,n2= n3
● display n3
● stop
code:-
#include< stdio.h>
#include< conio.h>
Void main()
{
int i,n,n1= 0,n2= 1,n3;
Clr scr ()
Pr intf(“Enter the number :”);
Scanf(“%d”,&n);
Pr intf(“The fibonnaci ser ies :\n”);
Pr intf(“%d \n”,n2);
for (i= 3;i< = n;i+ + )
{
n3= n1+ n2;
pr intf(“%d \n”,n3);
n1= n2;
n2= n3;
}
getch();
}
Output:-
Input number
NO Yes
I f ( &&c
ch h <
A’ Z’ )
>=
=’
’
display Display
UPPERCASE CHARACTER
not an alphabet
end
Algor ithm:-
● star t
● input number
● if(ch> = ’A’&&ch< = ’Z’) it is tr ue then display UPPERCASE
CHARACTER
● else not an alphabet
● end
Code:-
#include< stdio.h>
#include< conio.h>
Void char accheck(char ch)
{
If(ch> = ’A’&&ch< = ’Z’)
{
Pr intf(“UPPERCASE CHARACTER\n”);
}
Else
Pr intf(“is not an alphabet\n”);
}
Int main()
{
char c;
pr intf(“Enter any char acter \n”);
scanf(“%c”,&c);
char accheck(c);
getch();
r etur n 0;
}
Output:-
Q.9 Wr ite a pr ogr am in c to function to check lower case letter .
Ans.
Algor ithm:-
● star t
● input number
● if(ch> = ’a’&&ch< = ’z’) it is tr ue then display LOWERCASE
CHARACTER.
● else not an alphabet
● end
Flowchar t:-
star t
Input number
I f ( &c
NO Yes
ch h <
a’
&
>=
=’
z’ )
display
not an alphabet
Display
LOWERCASE CHARACTER
Code:-
#include< stdio.h>
#include< conio.h>
Void char accheck(char ch)
{
If(ch> = ’a’&&ch< = ’z’)
Pr intf(“LOWERCASE CHARACTER\n”);
Else
Pr intf(“is not an alphabet\n”);
}
Int main()
{
char c;
pr intf(“Enter any char acter \n”);
scanf(“%c”,&c);
char accheck(c);
getch();
r etur n 0;
}
Output:-
star t
Input number
If
Yes No
(n > n
&n
1> 3)
1
=
n2
&
Display n1lar gest Yes If ( No
) n2
>=
n3
stop
Algor ithm:-
● star t
● input number s
● check condition if(n1> = n2&&n1> = n3) it is tr ue then display n1
lar gest
● if(
Code:-
#include< stdio.h>
#include< conio.h>
Int main()
{
Int n1,n2,n3;
Pr intf(“Enter thr ee number s:”);
Scanf(“%d%d%d”,&n1,&n2,&n3);
If(n1> = n2)
{
If(n1> = n3)
Pr intf(“\n n1lar gest”);
else
pr intf(“\n n3 lar gest”);
}
else
{
If(n2> = n3)
Pr intf(“\n n2 lar gest”,n2);
else
{
Pr intf(“\n n3 lar gest”,n3);
}
r etur n 0;
}
Output:-
Q.11Wr ite a pr ogr am in c to ty pe casting implicit explicit.
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
Int x= 10;
Float y = 10.4;
Int z;
Float w;
z= x+ y ;//implicit
w= (float)x+ y ;// explicit
pr intf(“%d\n”,z);
pr intf(“%f”,w);
getch();
}
Output:-
Output :-
c).
*
* *
* * *
Ans.
# include< stdio.h>
# include< conio.h>
Void main( )
{
Int n;
Int r ,j ,k;
Clr scr ( );
Pr intf(“Enter the number of r ows\n”);
Scanf(“%d”,&n);
for (r = 1; r < = n; r + + ){
for (j = n-r ; j > = 1; j --){
pr intf(“ “)
}
for (k= 1; k< = r ; k+ + ){
pr intf(“* ”);
}
Pr intf(“\n”);
}
getch( );
}
Output:-
d).
1
11
12 1
13 3 1
14 6 4 1
#include< stdio.h>
#include< conio.h>
void main()
{
Clr scr ();
Int r ow,col,space,n,no;
Pr intf(“enter any number :”)
Scanf(“%d”,&no)
for (r ow= 0 ; r ow< no; r ow+ + )
{
{
pr intf(“”);
}
n= 1; for (col= 0 ; col< = r ow; col+ + ) {
pr intf(“%d”,n);
n= n*(r ow-col)/(col+ 1);
}
pr intf(“\n”);
}
getch();
}
Output:-
Q.14 Wr ite a pr ogr am to input fr om user (5 subjects) sum,aver age.
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
Int mar ks,sub,count,sum= 0;
Float avg= 0.0;
Pr intf(“Enter number of subjets\n”);
Scanf(“%d”,&sub);
Pr intf(“Enter %d Subjects mar ks\n”,sub);
For (count= 1;count< = sub;count+ + )
{
Scanf(“%d”&mar ks);
Sum= sum+ mar ks;
}
Avg= sum/sub;
Pr intf(“sum= %d\nAver age = %0.2f\n”,sum,avg);
getch();
}
Output:-
Q.15 Wr ite a pr ogr am to pr int student mar ksheet.
Ans.
#include< stdio.h>
#include< conio.h>
Stur ct student
{
Char name[ 50] ;
Int mar ks[ 5] ;
Long int r ollno;
};
Int main()
{
Clr scr ();
Str uct student a;
Int i,sum= 0,per ;
Pr intf(“Enter student name:”);
Gets(a.name);
Pr intf(“\nEnter student r oll no.:”);
Scanf(“%d”,&a.r ollno);
Pr intf(“\n Enter student mar ks\n”);
For (i= 0;i< 5;i+ + )
{
Pr intf(“\n Enter %d subject mar ks:”i+ 1);
Scanf(“%d”,&a.mar ks[ i] );
}
For (i= 0;i< 5;i+ + )
Sum= sum+ a.mar ks[ i] ;
Per = sum/5;
Clr scr ();
Pr intf(“\n STUDENT NAME :%s”,a.name);
Pr intf(“\n STUDENT ROLL NO. :%ld”,a.r ollno);
Pr intf(“\n OBTAINED MARKS :500”);
Pr intf(“\n TOTAL MARKS :%d”,sum);
Pr intf(“\n PERCENTAGE :%d”,per );
Pr intf(“\n DIVISION : ”);
if(per > 100)
{
Pr intf(“\n invalid per cent”);
}
else if(per > = 60)
{
Pr intf(“\n fir st division”);
}
else if(per < 60&&per > = 50) {
pr intf(“second division”);
}
else if(per < 50&&per > = 40) {
pr intf(“\m thir d division”);
}
else
{
Pr intf(“\n You ar e fail”);
}
getch();
r etur n 0;
}
Output:-
Q16. Wr ite a pr ogr am to calculate simple inter est.
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
float amt,r ate,time,si;
clr scr ();
pr intf(“Enter the amount:”);
scanf(“%f”,&amt);
pr intf(“Enter the r ate:”);
scanf(“%f”,&r ate);
pr intf(“Enter the time:”);
scanf(“%f”,&time);
si= (amt*r ate*time/100);
pr intf(“\nSimple inter est= %f”,si);
getch();
}
Output:-
Q.17 Wr ite a pr ogr am in which y ou declar e var iable of all data ty pes
suppor ted by C language. Get input fr om user and pr int the value of each
var iable with alignment left, r ight and column width 10 . For r eal number s
pr int their values with two digits r ight to the decimal.
Ans.
#include< stdio.h>
#include< conio.h>
void main() {
char c;
int i;
float f;
double k;
pr intf(" Enter any char acter :" );
scanf(" %c" ,&c);
pr intf(" \n Enter any number i= " );
scanf(" %d" ,&i);
pr intf(" \n Enter any r eal no. f= " );
scanf(" %f" ,&f);
pr intf(" \n Enter any double float value k= " );
scanf(" %lf" ,&k);
pr intf(" \n %10 c" ,c);
pr intf(" \n %0 10 d" ,i);
pr intf(" \n %.2f" ,f);
pr intf(" \n %10 .2lf" ,k);
getch();
}
Output:-
Q.18. Wr ite a pr ogr am to demonstr ate multiplication table input fr om user
till 10 .
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
Int n,I;
Clr scr ();
Pr intf(“Enter any no:”);
Scanf(“%d”,&n);
Pr intf(“Multiplication table of %d\n”,n);
For (i= 1;i< = 10;i+ + )
{
Pr intf(“%d*%d= %d\n”,n,I,(n*i));
}
getch();
}
Output:-
Q. 19. Wr ite a pr ogr am to demonstr ate addition of two matr ix.
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
Int a[ 3] [ 3] ,b[ 3] [ 3] ,c[ 3] [ 3] ,I,j;
Clr scr ();
Pr intf(“enter the element of the fir st matr ix\n”);
For (i= 0;i< 3;i+ + )
{
For (j= 0;j< 3;j+ + )
{
Scanf(“%d”,&a[ i] [ j] );
}
}
Pr intf(“enter the element of second matr ix\n”);
For (i= 0;i< 3;i+ + )
{
For (j= 0;j< 3;j+ + )
{
Scanf(“%d”,&a[ i] [ j] );
}
}
Pr intf(“The fir st matr ix is\n”);
For (i= 0;i< 3;i+ + )
{
For (j= 0;j< 3;j+ + )
{
pr intf(“%d\t”,&a[ i] [ j] );
}
Pr intf(“\n”);
}
Output:-
Q.21Wr ite a pr ogr am to get input fr om user and check matr ix then
matr ix multiplication or pr int not matr ix.
Ans.
#include< stdio.h>
#include< conio.h>
#include< stdlib.h>
Void main()
{
Int a[ 2] [ 2] ,b[ 2] [ 2] ,c[ 2] [ 2] ;
Int r 1,c1,r 2, c2,i,j,k,;
st
Pr intf(“Enter the r ow and column of 1 matr ix\n”);
Scanf(“%d%d”,&r 1,&c1);
nd
Pr intf(“Enter the r ow and column of 2 matr ix\n”);
Scanf(“%d%d”&r 2,&c2);
If(c1!= r 2)
{
Pr intf(“\n Matr ices ar e not multiplicable”);
Exit(0);
}
Pr intf(“\n Enter the element of fir st matr ix\n”);
for (i= 0;i< r 1;r + + )
{
for (j= 0;j< c1;j+ + )
{
Scanf(“%d”,a[ i] [ j] );
}
}
pr intf(“\n enter the element of second matr ix\n”);
for (i= 0;r < r 2;i+ + )
{
for (j= 0;j< c2;j+ + )
{
Scanf(“%d”,&b[ i] [ j] );
}
}
pr intf(“The fir st matr ix is\n”);
for (i= 0;i< r 1;i+ + )
{
for (j= 0;j< c1;j+ + )
{
pr intf(“%d\t”,a[ i] [ j] );
}
pr intf(“\n”);
}
pr intf(“The second matr ix is\n”);
for (i= 0;i< r 2;i+ + )
{
for (j= 0;j< c2;j+ + )
{
pr intf(“%d\t”,b[ i] [ j] );
}
pr intf(“\n”);
}
for (i= 0;i< r 1;i+ + )
{
for (j= 0;j< c2;j+ + )
{
S= 0;
for (k= 0;k< c1;k+ + )
{
s= s+ a[ i] [ k] *b[ k] [ j] ;
c[ i] [ j] = s;
}
}
}
pr intf(“Multiplication of two matr ix\n”);
for (i= 0;i< r 1;i+ + )
{
for (j= 0;j< c2;j+ + )
pr intf(“%d\t”,c[ i] [ j] );
pr intf(“\n”);
}
getch();
}
Output:-
Q. 22 Wr ite a pr ogr am to pr int compar e two number s using ter nar y
oper ator s.
Ans.
#include< stdio.h>
#include< conio.h>
void main()
{
Int a,b,c;
pr intf(“enter two number ”);
scanf(“%d”,&a,&b);
c= ((a> b)?a:b);
pr intf(“%d is gr eater ”,c);
getch();
}
Q.23. Wr ite a pr ogr am to conver t temper atur e fr om centigr ate to
far enhiet.
Ans.
#include< stdio.h>
#include< conio.h>
void main()
{
float c,f;
pr intf(“\n Enter temper atur e in centigr ate:”);
scanf(“%d”,&c);
f= (c*9/5)+ 32;
pr intf(“\n Temp in fah= %f”,f);
getch();
}
Output:-
Q.24 Wr ite a pr ogr am to demonstr ate betwise oper ator left shift and
r ight shift oper ator .
Ans.
#include< stdio.h>
#include< conio.h>
void main()
{
Int a= 4,c;
c= a< < 1;
pr intf(“%d”,c);
c= a> > 1;
pr intf(“%d”,c);
getch();
}
Output:-
Q.25 Wr ite a pr ogr am to demonstr ate pr int to incr eament and
decr eament oper ator .
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
int x= 5;
clr scr ();
x+ + ; //post incr ement oper ator
pr intf(“x= %d”,x);
+ + x; //pr e incr ement oper ator
pr intf(“x= %d”,x);
x--; //post decr ement oper ator
pr intf(“x= %d”,x);
--x; //pr e decr ement oper ator
pr intf(“x= %d”,x);
getch();
}
Output:-
Q. 26. Wr ite a pr ogr am to calculation of sum of the digit.
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
int n,r ,sum= 0;
pr intf(“enter a number \n”);
scanf(“%d”,&n);
while(n> 0)
{
r = n%10;
sum= sum+ r ;
n= n/10;
}
pr intf(“sum of digit of enter ed number %d”,sum);
getch();
}
Output:
Q.27 Wr ite a pr ogr am to r ever se a str ing without using libr ar y
function.
Ans.
#include< stdio.h>
#include< conio.h>
Void main()
{
char a[ 15] ,temp;
int I,j,l= o;
clr scr ();
pr intf(“enter the str ing :”);
scanf(“%s”,a);
for (i= 0;a[ i] != ’\0’;i+ + )
l+ + ;
i= 0;
j= l-1;
while(i< j)
{
temp= a[ i] ;
a[ i] = a[ j] ;
a[ j] = temp;
i+ + ;
j+ + ;
}
pr intf(“r ever se str ing = %s”,a);
getch();
}
Output:-
Output:-
Q.29 wr ite a pr ogr am demonstr ate to call by r efer ence.
Ans.
#include< stdio.h>
#include< conio.h>
void add(int *a);
void main()
{
int x;
pr intf(“enter any number ”);
scanf(“%d”,&x);
add(&x);
pr intf(“\n after calling function var iable value is %d”,x);
getch();
}
Void add(int *a)
{
*a= *a+ 10;
pr intf(“\n in Called function var iable value is %d”,*a);
}
Output:-
br eak;
case 3:
pr intf(" please enter the lenght of the r ectangle:" );
scanf(" %f" ,&length);
pr intf(" enter the br eadth of the r ectangle:" );
scanf(" %f" ,&br eadth);
ar ea= length*br eadth;
pr intf(" \nAr ea of r ectangle: %f" ,ar ea);
br eak;
default:
pr intf(" invalid choice" );
}
}
Output:-
Q.31wr ite pr ogr am in c to calculate volume using function.
Ans.
#include< stdio.h>
#include< conio.h>
float pi= 3.14;
int cube(int a);
int cuboid(int l,int w,int h);
int spher e(int r );
void main()
{
int i,j,k,l,d,V;
pr intf(" Find volume of some shapes\n" );
pr intf(" \n CUBE\n" );
cube(i);
pr intf(" \n CUBOID\n" );
cuboid(j,k,l);
pr intf(" \n SPHERE\n" );
spher e(d);
}
int cube(int a)
{
pr intf(" Enter side of the cube\n" );
scanf(" %d" ,&a);
pr intf(" Volume of cube is: %d\n" ,a*a*a);
r etur n 0;
}
int cuboid(int l,int w,int h)
{
pr intf(" Enter length of cuboid\n" );
scanf(" %d%d%d" ,&l,&w,&h);
pr intf(" Volume is cuboid: %d\n" ,l*w*h);
r etur n 0;
}
int spher e(int r )
{
pr intf(" Enter r adius of spher e\n" );
scanf(" %d" ,&r );
pr intf(" Volum of spher e is:%f" ,4/3*pi*r *r *r );
r etur n 0;
Output:-
Q.32 Wr ite a pr ogr am in c to sear ch an element for m ar r ay by linear
ser ach method.
Ans.
#include< stdio.h>
#include< conio.h>
void main()
{
int i,n,sear ch,count= 0;
pr intf(" \n\t Enter number of element in ar r ay " );
scanf(" %d" ,&n);
int ar r [ n] ;
pr intf(" \n\t Enter %d number " ,n);
for (i= 0;i< n;i+ + )
{
scanf(" %d" ,&ar r [ i] );
}
pr intf(" \n\t Enter a number to sear ch" );
scanf(" %d" ,&sear ch);
for (i= 0;i< n;i+ + )
{
if(ar r [ i] = = sear ch)
{
pr intf(" \n\t %d pr esent at location %d" ,sear ch,(i+ 1));
count+ + ;
}
}
if(count= = 0)
{
pr intf(" \n\t %d is not pr esent in ar r ay " ,sear ch);
}
else
{
pr intf(" \n\t %d is pr esent %d times in ar r ay " ,sear ch,count);
}
}
Output:-
Q.33 Wr ite a pr ogr am to find tr anspose of matr ix.
Ans.
#include< stdio.h>
#include< conio.h>
void main()
{
int a[ 2] [ 2] ,i,j,m,n;
pr intf(" number of r ows\n" );
scanf(" %d" ,&m);
pr intf(" number of columns\n" );
scanf(" %d" ,&n);
pr intf(" Enter element of matr ix\n" );
for (i= 0;i< m;i+ + )
{
for (j= 0;j< n;j+ + )
{
scanf(" %d" ,&a[ i] [ j] );
}
}
pr intf(" Matr ix is \n" );
for (i= 0;i< m;i+ + )
{
for (j= 0;j< n;j+ + )
{
}
pr intf(" Tr anspose of matr ix\n" );
for (i= 0;i< m;i+ + )
{
for (j= 0;j< n;j+ + )
{
pr intf(" %d\t" ,a[ j] [ i] );
}
pr intf(" \n" );
}
}
Output:-
Q.34 Wr ite a pr ogr am to input a str ing and find it’s length without
using libr ar y function.
Ans.
#include< stdio.h>
#include< conio.h>
void main()
{
char a[ 15] ;
int i,l= 0;
pr intf(" \n enter the str ing :" );
scanf(" %s" ,a);
for (i= 0;a[ i] != '\0';i+ + )
l+ + ;
pr intf(" \n length= %d" ,l);
getch ();
}
Output:-
Q.35 wr ite pr ogr am to check whether the enter str ing palindr ome or
not.
Ans.
#include< stdio.h>
#include< conio.h>
#include< str ing.h>
int main()
{
char str [ 50] ;
int i,len,flag= 0;
pr intf(" \n Enter the str ing to check for palindr ome" );
scanf(" %s" ,str );
len= str len(str );
for (i= 0;i< len;i+ + )
{
if(str [ i] != str [ len-i-1] )
{
flag= 1;
br eak;
}
}
if (flag= = 0)
pr intf(" str ing is palindr ome" );
else
pr intf(" str ing is not a palindr ome" );
getch();
r etur n 0;
}
Output:-
Q.36 Wr ite a pr ogr am to calculate r ever se str ing and length str ing
help with libr ar y function.
Ans.
#include< stdio.h>
#include< conio.h>
#include< str ing.h>
void main()
{
char str [ 100] ;
int i;
pr intf(" Enter the str ing: " );
scanf(" %s" ,str );
pr intf(" Rever se of str is %s\n" ,str r ev(str ));
pr intf(" length of sting is %d" ,str len(str ));
getch();
}
Output:-
Q.37 Wr ite a pr ogr am in c to input and pr int details of an employ ee
the id,name,salar y using str uctur e.
Ans.
#include< stdio.h>
#include< conio.h>
str uct employ ee
{
char name[ 100] ;
int id;
float salar y ;
};
void main()
{
str uct employ ee emp;
pr intf(" Enter detials of employ ee:\n" );
pr intf(" Enter employ ee name:" );
scanf(" %s" ,&emp.name);
pr intf(" Enter employ ee id:" );
scanf(" %d" ,&emp.id);
pr intf(" Enter employ ee salar y :" );
scanf(" %f" ,&emp.salar y );
pr intf(" Detials of employ ee\n" );
pr intf(" Name :%s\n" ,emp.name);
pr intf(" Id :%d\n" ,emp.id);
pr intf(" salar y :%f\n" ,emp.salar y );
getch();
}
Output:-
}
pr intf(" \n" );
pr intf(" Name\t Rollno.\tmar ks\n\n" );
Output:-
Q.39 Wr ite a pr ogr am in c to demonstr ate pointer to a pointer (double
pointer ).
Ans.
#include< stdio.h>
#include< conio.h>
int main()
{
int a= 10;
int *p;
int **pp;
p= &a; // pointer is pointing to the addr ess of a
pp= &p; // pointer pp is a double pointer pointing to the adr ess of
pointing p
pr intf(" addr ess of a: %x\n" ); // adr ess of a will be pr inted
pr intf(" addr ess of p: %x\n" ,pp); // adr ess of p will be pr inted
pr intf(" value stor ed at p: %d\n" ,*p);
pr intf(" value stor d at pp: %d\n" ,**pp);
getch();
}
Output:-
Q.40 Wr ite a pr ogr am to demonstr ate the use of malloc and r ealloc in.
Ans.
Code:-
#include< stdio.h>
#include< stdlib.h>
str uct cour se
{
char subjects[ 100] ;
int mar ks;
};
int main()
{
str uct cour se*ptr ;
int i,n;
pr intf(" \nenter the r ecor ds:" );
scanf(" %d" ,&n);
ptr = (str uct cour se*)malloc(n* sizeof(str uct cour se));
for (i= 0;i< n;+ + i)
{
pr intf(" \nenter the %d no of r ecor ds:" ,i+ 1);
pr intf(" \nenter the subjects:" );
scanf(" %s" ,&(ptr + i)-> subjects);
pr intf(" \nenter the mar ks:" );
scanf(" %d" ,&(ptr + i)-> mar ks);
}
pr intf(" \ndisplay ed cour se r ecor d:" );
for (i= 0;i< n;i+ + )
{
pr intf(" \nsubjects= %s" ,(ptr + i)-> subjects);
pr intf(" \nmar ks= %d" ,(ptr + i)-> mar ks);
}
pr intf(" \n------------------------------------------------------" );
pr intf(" \nenter the new r ecor ds y ou want to cr eate:" );
scanf(" %d" ,&n);
ptr = (str uct cour se*)r ealloc(ptr ,n* sizeof(str uct cour se));
for (i= 0;i< n;i+ + )
{
pr intf(" \nenter the %d no of r ecor ds:" ,i+ 1);