You are on page 1of 35

Semester- 1st

Subject: - Programming in C
Lab Manual
Contents
SL NO

NAME OF THE PROGRAM

Write a C Program swapping of Two Number with using Third Variable

Write a C Program swapping of Two Numbers without using 3rd variable.

Write a C Program find the simple interest

Write a C Program convert cellceius


ce
to ferhenit

Write a C Program of Grading System

Write a C Program to find the Roots of Quadratic Equation

Write a C programme find the sum of individual digits of a positive integer.

Write a C Program Reverse of a number

Write a C Program count the digits from a Number

10

Write
rite a C Program input a number, find the factorial of given no.

11

Write a C program Print the Fibonacci Series

12

Write a C Program input a number ,check the no is palindrome or not

13

Write a C Program input a number, check the no is Armstrong or not.

14

Write a C Program to find LCM

10

15

Write a C Program input a number, check the no is prime or not.

10

16

Write a C Program find prime no between 1 to 100.

11

17

Write a C Program input a number,


numb check the no is perfect or not

11

18

Write a C Program Evaluate the Series s=1 - x^2/2!+x^4/4!+.......+x^n/n!

12

19

Write a C program Display Floyd Triangle

12

20

Write a C Program print the pattern-1


pattern

13

21

Write a C Program print the pattern-2


pattern

13

22

Write a C Program print the pattern-3


pattern

14

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

PAGE NO

Page 1

Semester- 1st
Subject: - Programming in C
Lab Manual
23

Writee a C program to find the sum of elements from array

15

24

Write a C program insert an element into the array

16

25

Write a C program Delete an element from the array

17

26

Write a C program search an element from list of integers

18

27

Write a C Program sorting the List of integers

19

28

Write a C program merging of two arrays

20

29

Write a C Program find the large and smallest no form list of integers
int

21

30

Write a C Program Transpose of Matrix

22

31

Write a C Program sum of the diagonal elements of the matrix

23

32

Write a C Program Perform Addition of two Matrix

24

33

Write a C Program
ogram Perform Matrix Multiplication

25

34

26

36

Write a C Program find the sum of individual digits of a positive integer


using function
ion name SUM.
Write a C program input a number, check the no is Armstrong or not using
function name ARM.
Write a C program find the length of string without using string
string function

37

Write a C program reverse of string without using string function

28

38

Write a C program convert upper case to lower case

29

39

Write a C program convert lower case to upper case

29

40

Write a C Program input a string, check the string is palindrome or not

30

41

31

42

Write a C Program to input a string count the no of alphabets, digits,


vowels present in string.
Write a C Program Concatenation of Two String

43

Write a C Program print the string pattern

32

44

Write a C Program display the Student Details using Structure

33

45

Write a C program Addition of two complexes no.

33

46

Write a C Program to display Student detail with address


addres using Nested
Structure

34

35

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

27
28

32

Page 2

Semester- 1st
Subject: - Programming in C
Lab Manual
1. Write a C Program swapping of Two Number with using Third Variable
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
Int a,b,c;
Clrscr();
Printf(\n
n Enter the value of a and b:);
Scanf(%d%d,&a,&b);
C=a;
a=b;
b=c;
printf(\n
n Swapping of two numbers :%d\t%d,a,b);
:%d
getch();
}

2. Write a C Program swapping of Two Numbers without using 3rd variable.


Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf(\n enter a nad b);
scanf(%d%d,&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf(\n
n swapping of two numbers:%d%d,a,b);
getch();
}
(Note: way-2 a=a^b;b=a^b;a=a^b
Way-3 a=a*b; b=a/b; a=a/b;)

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 3

Semester- 1st
Subject: - Programming in C
Lab Manual
3. Write a C Program find the simple interest
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
Int p,t,r;
Float si;
Clrscr();
Printf(\n Enter p,r and t:);
Scanf(%d%d%d,&p,&t,&r);
Si=(p*t*r)/100;
Printf(Simplet Interst is:%f,si);
Getch();
}

4. Write a C Program convert celiceus to ferhenit


Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
Int f;
Float c;
Clrscr();
Printf(\n Enter ferhenit);
Scanf(%d,&f);
C=5/9*(f-32);
Printf(%f,c);
Getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 4

Semester- 1st
Subject: - Programming in C
Lab Manual

5. Write a C Program input three different subject marks, find total, avg.
If avg>=60 1st class
If avg>=50 and avg <=59 2nd Class
If avg>=40 and avg <=493rd Class
If avg<=39 Fail
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int m1,m2,m3,t,avg;
clrscr();
printf(\n enter three marks:);
scanf(%d%d%d,&m1,&m2,&m3);
t=m1+m2+m3;
avg=t/3;
if(avg>=60)
{
printf(1st class);
}
else if(avg>=50 && avg<=59)
{
printf(2nd class);
}
else if(avg>=40 && avg<=49)
{
printf(3rd class);
}
else
printf(fail);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 5

Semester- 1st
Subject: - Programming in C
Lab Manual
6. Write a C Program to find the Roots of Quadratic Equation
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float r1,r2;
clrscr();
printf("Enter the value of a,b and c:");
scanf("%d%d%d",&a,&b,&c);
d=(b*b)-(4*a*c);
if(d>0)
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\nRoots
nRoots Are:%f%f",r1,r2);
}
else
printf("Roots Are Imaginary");
getch();
}
7. Write a C programme find the sum of individual digits of a positive integer.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int no,rem,sum=0;
clrscr();
printf("\n Enter a No:");
scanf("%d",&no);
while(no>0)
{
rem=no%10;
sum=sum+rem;
no=no/10;
}
printf("\nSum
nSum of Indivisual Digits is:%d",sum);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 6

Semester- 1st
Subject: - Programming in C
Lab Manual
8. Write a C Program Reverse of a number
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int no,rem,rev=0;
clrscr();
printf(\n enter a number:);
scanf(%d,&no);
while(no!=0)
{
rem=no%10;
rev=rev*10+rem;
no=no/10;
}
printf(\n
n reverse of no is:%d,rev);
getch();
}

9. Write a C Program count the digits from a Number


Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int no,count=0;
clrscr();
printf(\n enter a number:);
scanf(%d,&no);
while(no!=0)
{
count++;
no=no/10;
}
printf(%d,count);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 7

Semester- 1st
Subject: - Programming in C
Lab Manual
10. Write a C Program input a number; find the factorial of given no.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int no,f=1;
clrscr();
printf("\nEnter
nEnter a Number:");
scanf("%d",&no);
while(no>0)
{
f=f*no;
no--;
}
printf("Factorial of a Number is:%d",f);
getch();
}
11. Write a C program Print the Fibonacci Series
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,c,n;
clrscr();
printf("\n Enter The Range:");
scanf("%d",&n);
printf("%d%d",a,b);
while(n>2)
{
c=a+b;
printf("%d",c);
a=b;
b=c;
n--;
}
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 8

Semester- 1st
Subject: - Programming in C
Lab Manual
12. Write a C Program
am input a number ,check the no is palindrome or not
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int no,rem,rev=o,x;
clrscr();
printf(\n
n enter a number:);
scanf(%d,&no);
x=no;
while(x>0)
{
rem=x%10;
rev=rev*10+rem;
x=x/10;
}
if(no==rev)
printf(no is palindrome);
else
printf(not a palidrome);
getch();
}
13. Write a C Program input a number, check the no is Armstrong or not.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int no,x,rem,s=0;
clrscr();
printf(\n enter a number:);
scanf(%d,&no);
x=no;
while(x>0)
{
rem=x%10;
s=s+(rem*rem*rem);
x=x/10;
}
if(no==s)
printf(no is armstrong);
else
printf(no); getch(); }
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 9

Semester- 1st
Subject: - Programming in C
Lab Manual
14. Write a C Program to find LCM
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int n1,n2,x,y;
clrscr();
printf("\nEnter
nEnter two numbers:");
scanf("%d %d",&n1,&n2);
x=n1,y=n2;
while(n1!=n2){
if(n1>n2)
n1=n1-n2;
else
n2=n2-n1;
}
printf("L.C.M=%d",x*y/n1);
getch();
}
15. Write a C Program input a number, check the no is prime or not.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num,c=0;
clrscr();
printf("enter a number");
scanf("%d",&num);
while(i<=num)
{
if(num%i==0)
i=i+1;
c=c+1;
}
if(c==2)
printf("prime no is %5d",num);
else
printf("not a prime %d",num);
}
getch();
}
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 10

Semester- 1st
Subject: - Programming in C
Lab Manual
16. Write a C Program find prime no between 1 to 100.
100
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num=1;
clrscr();
while(num<=100)
{
i=2;
while(i<=num)
{
if(num%i==0)
break;
i++;
}
if(i==num)
printf("\n%d is Prime",num);
num++;
}
getch();
}
17. Write a C Program input a number, check the no is perfect or not
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,s;
clrscr();
printf("\n enter a number");
scanf("%d",&n);
i=1;
s=0;
while(i<n)
{
if(n%i==0)
s=s+i; i++; }
if(s==n) printf("%d is Perfect Number",n);
else
printf("%d is not Perfect Number",n);
getch();
}
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 11

Semester- 1st
Subject: - Programming in C
Lab Manual
18. Write a C Program Evaluate the Series s=1 - x^2/2!+x^4/4!+.......+x^n/n!
^2/2!+x^4/4!+.......+x^n/n!
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,x,n,c=0,f=1;
float s=1;
clrscr();
printf("Enter the value of x and n:");
scanf("%d%d",&x,&n);
for(i=2;i<n;i++)
{
f=f*i;
c=i/2;
if(c%2==0)
{
s=s+pow(x,i)/f;
}
else
s=s-pow(x,i)/f;
}
printf("Evaluation is: %f",s);
getch();
}
19. Write a C program Display Floyd Triangle
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k=1;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=1;i<n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",k++);
} printf("\n"); } getch(); }
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 12

Semester- 1st
Subject: - Programming in C
Lab Manual
20. Write a C Program Print the pattern
*
**
***
****
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j,n;
clrscr();
printf(\n
n enter the limit:);
scanf(%d,&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf(*);
}
printf(\n);
}
getch();
}
21. Write a C Program Print the pattern
1
12
123
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j,n;
clrscr();
printf(\n
n enter the limit:);
scanf(%d,&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf(%d,j);
} printf(\n); } getch(); }
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 13

Semester- 1st
Subject: - Programming in C
Lab Manual
22. Write a C Program Print the pattern
pa
1
11
111
1111
111
11
1
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j,n;
clrscr();
printf(\n
n enter the limit:);
scanf(%d,&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf(1);
}
printf(\n);
}
for(i=n;i>0;i--)
{
for(j=0;j<=i;j++)
{
printf(1);
}
printf(\n);
}
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 14

Semester- 1st
Subject: - Programming in C
Lab Manual
23. Writee a C program to find the sum of elements from array.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,sum=0,n;
clrscr();
printf(\ enter the size of array);
scanf(%d,&n);
printf(\n
n enter the data into the array:);
for(i=0;i<n;i++)
{
scanf(%d,&a[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf(%d,sum);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 15

Semester- 1st
Subject: - Programming in C
Lab Manual
24. Write a C program insert an element into the array
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,pos,item;
clrscr();
printf("Enter the sizee of array:");
scanf("%d",&n);
printf("\nEnter
nEnter Datas into Array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter
nEnter the position of element:");
scanf("%d",&pos);
printf("\nEnter
nEnter the item to be inserted:");
scanf("%d",&item);
for(i=pos-1;i<n;i++)
{
a[i+1]=a[i];
}
a[pos-1]=item;
printf("\nAfter
nAfter Insertion of New element:");
for(i=0;i<(n+1);i++)
printf("%d\t",a[i]);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 16

Semester- 1st
Subject: - Programming in C
Lab Manual
25. Write a C program Delete an element from the array
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,pos;
clrscr();
printf("Enter the size of array:");
scanf("%d",&n);
printf("\nEnter
nEnter Datas into Array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter
nEnter the position of element:");
scanf("%d",&pos);
for(i=pos-1;i<n;i++)
{
a[i-1]=a[i];
}
printf("\nAfter Deletion of element from array:");
for(i=0;i<(n-1);i++)
printf("%d\t",a[i]);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 17

Semester- 1st
Subject: - Programming in C
Lab Manual
26. Write a C program search an element from list of integers.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,item,n;
clrscr();
printf(\n enter the size of array:);
scanf(%d,&n);
printf(\n
n enter datas into array:);
for(i=0;i<n;i++)
{
scanf(%d,&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]==item)
{
printf(\n
n position of element is:%d,i);
break;
}
}
if(i==n)
printf(\n
n the no is not present in the list);
li
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 18

Semester- 1st
Subject: - Programming in C
Lab Manual
27. Write a C Program sorting the List of integers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,n,temp;
clrscr();
printf("Enter the size of array:");
scanf("%d",&n);
printf("\nEnter
nEnter Datas into Array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}}
printf("\nSorting of Element :");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 19

Semester- 1st
Subject: - Programming in C
Lab Manual
28. Write a C program merging of two arrays.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],i,j,m,n,temp;
clrscr();
printf("Enter the size of array:");
scanf("%d\t%d",&m,&n);
printf("\nEnter Datas into Array--1:");
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
printf("\nEnter Datas into Array--2:");
for(j=0;j<n;j++)
{
scanf("%d",&b[j]);
}
printf("\nMerging
nMerging of Two Arrays:");
for(i=m,j=0;i<(m+n);i++,j++)
{
a[i]=b[j];
}
for(i=0;i<(m+n);i++)
printf("%d\t",a[i]);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 20

Semester- 1st
Subject: - Programming in C
Lab Manual
29. Write a C Program find the large and smallest no form list of integers
integers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,large,small,n;
clrscr();
printf("\n
n Enter the size of an array:");
scanf("%d",&n);
printf("\n
n Enter the Datas into array:");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
large=small=a[0];
for(i=0;i<n;i++)
{
if(a[i]>large)
{
large=a[i];
}
if(a[i]<small)
{
small=a[i];
}
}
printf("\n
n Largest No is:%d",large);
printf("\n
n Smallest NO is:%d",small);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 21

Semester- 1st
Subject: - Programming in C
Lab Manual
30. Write a C Program Transpose of Matrix
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j;
clrscr();
printf(enter data into the matrix:);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf(%d,&a[i][j]);
}
}
printf(\n
n transpose of matrix is:);
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf(%d,a[j][i]);
}
printf(\n);
}
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 22

Semester- 1st
Subject: - Programming in C
Lab Manual
31. Write a C Program sum of the diagonal elements of the matrix
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],i,j,sum=0;
clrscr();
printf(\n
n enter the data into matrix:);
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf(%d,&a[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j||(i+j==2))
{
sum=sum+a[i][j];
}
}
}
printf(\n
n sum of diagonal matrix is:%d,sum);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 23

Semester- 1st
Subject: - Programming in C
Lab Manual
32. Write a C Program Perform Addition of two Matrix
Program:
#include<stdio.h>
#include<conio.h>
void matrix(int[][3],int[][3]);
void main()
{
int a[3][3],b[3][3],i,j;
clrscr();
printf("Enter Datas into Array-1:");
1:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter Datas into Array-2:");
2:");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
matrix(a,b);
getch();
}
void matrix(int x[3][3],int y[3][3])
{
int i,j;
printf("Addition of Matrix is:\n");
n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",x[i][j]+y[i][j]);
}
printf("\n");
}
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 24

Semester- 1st
Subject: - Programming in C
Lab Manual
33. Write a C Program
ogram Perform Matrix Multiplication
Program:
#include<stdio.h>
#include<conio.h>
void mul(int[][2],int[][2]);
void main()
{
int a[2][2],b[2][2],i,j;
clrscr();
printf("Enter Datas into Array-1:");
1:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter Datas into Array-2:");
2:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}
mul(a,b);
getch();
}
void mul(int x[2][2],int y[2][2])
{
int z[2][2],i,j,k;
printf("Multiplication of Matrices is:\n");
is:
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<2;k++)
{
z[i][j]=0;
z[i][j]=z[i][j]+(x[i][k]*y[k][j]);
}}}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",z[i][j]);}printf("\n");
n");}getch();}
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 25

Semester- 1st
Subject: - Programming in C
Lab Manual
34. Write a C Program find the sum of individual digits of a positive integer using funct
function
name SUM.
Program:
#include<stdio.h>
#include<conio.h>
void sum(int);
void main()
{
int no;
clrscr();
printf(\n
n enter a number:);
scanf(%d,&no);
sum(no);
getch();
}
void sum(int x)
{
int rem,s=0;
while(x>0)
{
rem=x%10;
s=s+rem;
x=x/10;
}
printf(sumo
umo of digits:%d,s);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 26

Semester- 1st
Subject: - Programming in C
Lab Manual
35. Write a C program input a number, check the no is Armstrong or not using function
name ARM.
Program:
#include<stdio.h>
#include<conio.h>
int arm(int);
void main()
{
int no,s;
clrscr();
printf(\n
n enter a number:);
scanf(%d,&no);
s=arm(no);
if(s==no)
{
printf(armstrong no );
}
else
printf(not);
getch();
}
int arm(int x)
{
int rem,sum=0;
while(x>0)
{
rem=x%10;
sum=sum+rem*rem*rem;
x=x/10;
}
return(sum);
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 27

Semester- 1st
Subject: - Programming in C
Lab Manual
36. Write a C program find the length of string without using string
string function
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
int len=0,i;
clrscr();
printf(enter a string);
scanf(%s,a);
for(i=0;a[i]!=null;i++)
{
len++;
}
printf(length of string:%d,len);
getch();
}
37. Write a C program reverse of string without using string function
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
int len=0,i;
clrscr();
printf(\nenter
nenter a string:);
scanf(%s,a);
for(i=0;a[i]!=null;i++)
{
len++;
}
for(i=len-1;i>=0;i--)
{
printf(%c,a[i]);
}
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 28

Semester- 1st
Subject: - Programming in C
Lab Manual
38. Write a C program convert upper case to lower case
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
int i;
clrscr();
printf(\n
n Enter a string:);
scanf(%s,a);
for(i=0;a[i]!=null;i++)
{
a[i]=a[i]+32;
}
printf(%s,a);
getch();
}
39. Write a C program convert lower case to upper case
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
int i;
clrscr();
printf(\n
n Enter a string:);
scanf(%s,a);
for(i=0;a[i]!=null;i++)
{
a[i]=a[i]-32;
}
printf(%s,a);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 29

Semester- 1st
Subject: - Programming in C
Lab Manual
40. Write a C Program input a string, check the string is palindrome or not.
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20],b[20],i,j,k=0,l=0;
clrscr();
printf("\nEnter A String:");
scanf("%s",a);
for(i=0;a[i]!=NULL;i++)
{
l++;
}
for(i=l-1;i>=0;i--)
{
b[k++]=a[i];
b[k]=NULL;
}
if(strcmp(a,b)==0)
{
printf("String Palindrome");
}
else
printf("Not");
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 30

Semester- 1st
Subject: - Programming in C
Lab Manual
41. Write a C Program to input a string count the no of alphabets, digits, vowels present in
string.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
int alp=0, dig=0, v=0;
clrscr();
printf(\n
n enter a string);
scanf(%s,a);
for(i=0;a[i]!=null;i++)
{
if(a[i]>=65 && a[i]<= 90 ||a[i]>=97 && a[i]<= 122)
{
alp++;
}
if(a[i]>=48 && a[i]<=57)
{
dig++;
}
if(a[i]==a||a[i]==e||a[i]==i||a[i]==o||a[i]==u||a[i]==a||a[i]==e||a[i]==i||a[i]==o
||a[i]==u)
{
v++;
}
printf(%d%d%d,alp,dig,v);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 31

Semester- 1st
Subject: - Programming in C
Lab Manual
42. Write a C Program Concatenation of Two String
Program:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[10],b[10];
int l,m,i,j;
clrscr();
printf("Enter a String:");
gets(a);
printf("Enter a String:");
gets(b);
l=strlen(a);
m=strlen(b);
printf("\nString
nString Concatenation:");
for(i=l,j=0;i<=(l+m);i++,j++)
{
a[i]=b[j];
}
puts(a);
getch();
}
43. Write a C program print the string pattern
Program:
G
GC
GCE
GCEK
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20];
int len,i,j;
clrscr();
printf("\n Enter a String:"); gets(a);
len=strlen(a);
for(i=0;i<len;i++)
{
for(j=0;j<=i;j++) { printf("%c",a[j]); }printf("\n"); } getch(); }
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 32

Semester- 1st
Subject: - Programming in C
Lab Manual
44. Write a C Program display the Student Details using Structure.
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int roll;
char name[20];
int mark;
};
struct student s;
clrscr();
printf("Enter Roll No:");
scanf("%d",&s.roll);
printf("\nEnter Name:");
scanf("%s",s.name);
printf("\nEnter Mark:");
scanf("%d",&s.mark);
printf("\n
n Information about Student:");
printf("\nRoll:=%d\n",s.roll);
printf("\nName:=%s\n",s.name);
n",s.name);
printf("\nMark:=%d\n",s.mark);
getch();
}
45. Write a C program Addition of two complexes no.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
struct complex
{
int a,b,c,d, x,y;
}real,img;
clrscr();
printf("\nEnter Complex No-1:");
1:");
scanf("%d%d",&real.a,&img.b);
printf("\nEnter Complex No-2:");
2:");
scanf("%d%d",&real.c,&img.d);
real.x=real.a+real.c;
img.y=img.b+img.d;
printf("\nAddition
nAddition of Two COmplex No Is:");printf("%d+i%d",real.x,img.y);getch();
Is:");
getch();}
Prepared By: Asst.Professor.
t.Professor. Santosh Kumar Rath

Page 33

Semester- 1st
Subject: - Programming in C
Lab Manual
46. Write a C Program to display Student detail with address
address using Nested Structure
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int roll;
char name[20];
int mark;
struct address
{
char city[20];
char state[20];
int pin;
}a;
}s;
clrscr();
printf("Enter Roll No:");
scanf("%d",&s.roll);
printf("\nEnter
nEnter Name:");
scanf("%s",s.name);
printf("\nEnter Mark:");
scanf("%d",&s.mark);
printf("\nEnter City:");
scanf("%s",s.a.city);
printf("\nEnter State:");
scanf("%s",s.a.state);
printf("\nEnter Pin:");
scanf("%d",&s.a.pin);
printf("\nInformation
n about Student:");
printf("\nRoll:=%d\n",s.roll);
n",s.roll);
printf("\nName:=%s\n",s.name);
n",s.name);
printf("\nMark:=%d\n",s.mark);
n",s.mark);
printf("\nCity:=%s\n",s.a.city);
n",s.a.city);
printf("\nState:=%s\n",s.a.state);
n",s.a.state);
printf("\nPin:=%d\n",s.a.pin);
n",s.a.pin);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 34

Semester- 1st
Subject: - Programming in C
Lab Manual
47. Write a C Program to display 5 Student
S
detail.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int roll;
float mark;
}s[100];
int i;
clrscr();
printf("Enter Details of Students:");
for(i=0;i<5;i++)
{
scanf("%d%f",&s[i].roll,&s[i].mark);
}
printf("\nInformation
n about Student:");
for(i=0;i<5;i++)
printf("\nRoll :=%d\n",s[i].roll);
n",s[i].roll);
printf("\nMark:=%f\n",s[i].mark);
n",s[i].mark);
getch();
}

Prepared By: Asst.Professor.


t.Professor. Santosh Kumar Rath

Page 35

You might also like