C PROGRAMMING LAB MANUAL
Name:
Adm. No.:
Session 2018-19
INDEX
DATE OF
S. No. NAME OF PROGRAMME SIGNATURE REMARKS
EXECUTION
BASIC CONCEPTS
PROGRAM TO CALCULATE SUM OF 5 SUBJECTS AND
01
FIND PERCENTAGE
PROGRAM TO CONVERT TEMPERATURE FROM
02
DEGREE CENTIGRADE TO FAHRENHEIT
PROGRAM TO CALCULATE AREA AND
03
CIRCUMFERENCE OF A CIRCLE.
OPERATORS
PROGRAM TO FIND SUM OF FIRST AND LAST DIGIT
04
OF A FOUR DIGIT NUMBER
PROGRAM TO REVERSE THE DIGIT OF A FIVE DIGIT
05
NUMBER
PROGRAM TO FIND LARGER OF THREE NUMBER
06
USING CONDITIONAL OPERATOR
CONTROL STATEMENTS
PROGRAM TO FIND ROOTS OF A QUADRATIC
07
EQUATION
08 PROGRAM TO PRINT THE TABLE OF 1 TO 10
PROGRAM TO CHECK THE GIVEN YEAR IS LEAP
09
YEAR OR NOT
10 PROGRAM TO FIND PRIME NO. BETWEEN 1 TO 100
PROGRAM TO CHECK A GIVEN NUMBER IS
11
PALINDROME OR NOT
12 PATTERN-1
13 PATTERN-2
PROGRAM TO FIND OUT THE DAY FOR A GIVEN
14
DATE(BY USING SWITCH-CASE)
FUNCTION AND RECURSION
PROGRAM FOR FACTORIAL NUMBER USING
15
RECURSION
PROGRAM FOR FIBONACCI SERIES USING
16
RECURSION
PROGRAM FOR GCD OF TWO NUMBERS USING
17
RECURSION
ARRAY (1-D and 2-D)
PROGRAM FOR FINDING THE LARGEST AND
18
SMALLEST NUMBER IN A GIVEN ARRAY
19 PROGRAM FOR MULTIPLICATION OF TWO MATRIX
20 PROGRAM FOR BINARY SEARCH TREE
21 PROGRAM FOR BUBBLE SORT
STRINGS
PROGRAM FOR PRINTING AND FINDING THE
22
LENGTH OF STRING
PROGRAM FOR FINDING NUMBER OF VOWELS,
23 CONSONANTS, DIGITS AND SPACES
PROGRAM TO SORT ELEMENTS IN
24 LEXICOGRAPHICAL ORDER
PROGRAM TO REVERSE A STRING BY PASSING IT
25 TO FUNCTION
POINTERS
PROGRAM FOR FINDING THE SUM OF ARRAY
26
ELEMENT USING POINTER
PROGRAM FOR FINDING THE LENGTH OF STRING
27
USING POINTER
PROGRAM TO SWAP NUMBERS IN CYCLIC ORDER
28
USING CALL BY REFERENCE
STRUCTURE
CREATE A STRUCTURE TO STORE THE
29
INFORMATION OF STUDENTS
30 CREATE A STRUCTURE OF 10 EMPLOYEES
Assignment Index
DATE OF
S. No. NAME OF PROGRAMME SIGNATURE REMARKS
EXECUTION
01
02
03
04
05
Program no. 1
PROGRAM TO CALCULATE SUM OF 5 SUBJECTS AND FIND
PERCENTAGE
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int s1,s2,s3,s4,s5,sum,total=500;
float per;
printf("enter the marks of five subjects\n");
scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s4+s5;
printf("\n sum :%d",sum);
per=(sum*100)/total;
printf("\n percentage :%f",per);
getch();
return 0;
OUTPUT:
Program no. 2
PROGRAM TO CONVERT TEMPERATURE FROM DEGREE CENTIGRADE
TO FAHRENHEIT
#include<stdio.h>
#include<conio.h>
int main()
{
float celcius,farenheit ;
clrscr();
printf("enter temp in celcius\n");
scanf("%d",&celcius);
farenheit=(1.8*celcius+)32;
printf("\n Tempereture in farenheit :%d",farenheit);
getch();
return 0;
}
OUTPUT:
Program no. 3
PROGRAM TO CALCULATE AREA AND CIRCUMFERENCE OF A CIRCLE.
Code:
OUTPUT:
Program no.4
PROGRAM TO FIND SUM OF FIRST AND LAST DIGIT OF A FOUR DIGIT
NUMBER
OUTPUT:
Program no.5
PROGRAM TO REVERSE THE DIGIT OF A FIVE DIGIT NUMBER
#include<stdio.h>
int main()
{
int number, rev_num, next_digit,last_digit;
printf ("Enter the number that is to be reversed: ");
scanf("%d", &number);
last_digit = number - ((number / 10) * 10); /*units place*/
rev_num = last_digit; /* 5 */
next_digit = (number / 10) - ((number / 100) * 10); /*tenth's place*/
rev_num = (rev_num * 10) + next_digit; /*54*/
next_digit = (number / 100) - ((number / 1000) * 10); /*hundred's place*/
rev_num = (rev_num * 10) + next_digit; /*543*/
next_digit = (number / 1000) - ((number / 10000) * 10); /*thousand's place*/
rev_num = (rev_num * 10) + next_digit; /*5432*/
next_digit = (number / 10000) - ((number / 100000) * 10); /*ten thousand's place*/
rev_num = (rev_num * 10) + next_digit; /*54321*/
printf ("The Reversed Number is: %d",rev_num);
return 0;
}
OUTPUT:
Program no.6
PROGRAM TO FIND LARGER OF THREE NUMBER USING CONDITIONAL
OPERATOR
#include<stdio.h>
int main()
{
int a,b,c,big;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is:%d",big);
return 0;
OUTPUT:
Program no.7
PROGRAM TO FIND ROOTS OF A QUADRATIC EQUATION
OUTPUT:
Program no.8
PROGRAM TO PRINT THE TABLE OF 1 TO 10
OUTPUT:
Program no.9
PROGRAM TO CHECK THE GIVEN YEAR IS LEAP YEAR OR NOT
#include<stdio.h>
int main()
{
int year;
printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);
if ( year%400 == 0)
printf("%d is a leap year.\n", year);
else if ( year%100 == 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 == 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
return 0;
}
OUTPUT:
Program no.10
PROGRAM TO FIND PRIME NO. BETWEEN 1 TO 100
#include<stdio.h>
#include<conio.h>
int main()
{
int flag,x;
printf("1\t");
for(int i=1;i<=100;i++)
{
flag=0;
for(x=2;x<=i;x++)
{
if(i%x==0)
{
flag=1;
break;
}
else
continue;
}
if(i==x)
printf("%d\t",i);
}
getch();
}
OUTPUT:
Program no.11
PROGRAM TO CHECK A GIVEN NUMBER IS PALINDROME OR NOT
OUTPUT:
Program no.12
PROGRAM FOR GIVEN PATTERN
*
**
***
****
*****
#include <stdio.h>
int main()
{
int i,j,rows;
printf("Enter the number of rows: ");
scanf("%d",&rows);
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
printf("* ");
}
printf("\n");
}
return 0;
}
OUTPUT:
Program no.13
PROGRAM FOR GIVEN PATTERN
*
***
*****
*******
*********
OUTPUT:
Program no.14
PROGRAM TO FIND OUT THE DAY FOR A GIVEN DATE(BY USING
SWITCH-CASE)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int dd,mm,yy,year,month,day,i,n;
printf("enter the date:\n");
scanf("%d%d%d",&dd,&mm,&yy);
if(dd>31||mm>12)
{ printf("INVALID INPUT\n");
getch();
exit (0);
}
year=yy-1900;
year=year/4;
year=year+yy-1900;
switch(mm)
{
case 1:
case 10:
month=1;
break;
case 2:
case 3:
case 11:
month=4;
break;
case 7:
case 4:
month=0;
break;
case 5:
month=2;
break;
case 6:
month=5;
break;
case 8:
month=3;
break;
case 9:
case 12:
month=6;
break;
}
year =year + month;
year=year+dd;
day=year%7;
switch(day)
{
case 0:
//since 7%7=0 case 0 means it's a Saturday
printf("\n SATURDAY");
break;
case 1:
printf("\n SUNDAY");
break;
case 2:
printf("\n MONDAY");
break;
case 3:
printf("\n TUESDAY");
break;
case 4:
printf("\n WEDNESDAY");
break;
case 5:
printf("\n THURSDAY");
break;
case 6:
printf("\n FRIDAY");
break;
}
getch();
return 0;
}
OUTPUT:
Program no.15
PROGRAM FOR FACTORIAL NUMBER USING RECURSION
#include<stdio.h>
int fact(int n);
int main()
{
int n;
printf("enter the no\n");
scanf("%d",&n);
printf("factorial of the no is:");
printf("%d",fact(n));
return(0);
}
int fact(int n)
{
if(n==1 || n==0)
return 1;
else
return(n*fact(n-1));
}
OUTPUT:
Program no.16
PROGRAM FOR FIBONACCI SERIES USING RECURSION
OUTPUT:
Program no.17
PROGRAM FOR GCD OF TWO NUMBERS USING RECURSION
OUTPUT:
Program no.18
PROGRAM FOR FINDING THE LARGEST AND SMALLEST NUMBER IN A
GIVEN ARRAY
#include<stdio.h>
int main(){
int a[50],size,i,big,small;
printf("\nEnter the size of the array: ");
scanf("%d",&size);
printf("\nEnter %d elements in to the array: ", size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
big=a[0];
for(i=1;i<size;i++){
if(big<a[i])
big=a[i];
}
printf("Largest element: %d",big);
small=a[0];
for(i=1;i<size;i++){
if(small>a[i])
small=a[i];
}
printf("Smallest element: %d",small);
return 0;
}
OUTPUT:
Program no.19
PROGRAM FOR MULTIPLICATION OF TWO MATRIX
#include<stdio.h>
int main()
{
int a[10][10], b[10][10], c[10][10], i, j, k;
int sum = 0;
printf("\nEnter First Matrix : n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &a[i][j]);
}
}
printf("\nEnter Second Matrix:n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &b[i][j]);
}
}
printf("The First Matrix is: \n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf(" %d ", a[i][j]);
}
printf("\n");
}
printf("The Second Matrix is : \n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf(" %d ", b[i][j]);
}
printf("\n");
}
//Multiplication Logic
for (i = 0; i <= 2; i++) {
for (j = 0; j <= 2; j++) {
sum = 0;
for (k = 0; k <= 2; k++) {
sum = sum + a[i][k] * b[k][j];
}
c[i][j] = sum;
}
}
printf("\nMultiplication Of Two Matrices : \n");
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
printf(" %d ", c[i][j]);
}
printf("\n");
}
return (0);
}
OUTPUT:
Program no.20
PROGRAM FOR BINARY SEARCH TREE
#include<stdio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d integers\n", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d",&array[c]);
printf("Enter value to find\n");
scanf("%d",&search);
first = 0;
last = n - 1;
middle = (first+last)/2;
while( first <= last )
{
if ( array[middle] < search )
first = middle + 1;
else if ( array[middle] == search )
{
printf("%d found at location %d.\n", search, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if ( first > last )
printf("Not found! %d is not present in the list.\n", search);
return 0;
}
OUTPUT:
Program no.21
PROGRAM FOR BUBBLE SORT
#include<stdio.h>
int main(){
int s,temp,i,j,a[20];
printf("Enter total numbers of elements: ");
scanf("%d",&s);
printf("Enter %d elements: ",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
//Bubble sorting algorithm
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
return 0;
}
OUTPUT:
Program no.22
PROGRAM FOR PRINTING AND FINDING THE LENGTH OF STRING
OUTPUT:
Program no.23
PROGRAM FOR FINDING NUMBER OF VOWELS, CONSONANTS, DIGITS
AND SPACES
#include<stdio.h>
int main(){
char line[150];
int i,v,c,ch,d,s,o;
o=v=c=ch=d=s=0;
printf("Enter a line of string:\n");
gets(line);
for(i=0;line[i]!='\0';++i)
{
if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' ||
line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U')
++v;
else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
++c;
else if(line[i]>='0'&&c<='9')
++d;
else if (line[i]==' ')
++s;
}
printf("Vowels: %d",v);
printf("\nConsonants: %d",c);
printf("\nDigits: %d",d);
printf("\nWhite spaces: %d",s);
return 0;
}
OUTPUT:
Program no.24
PROGRAM TO SORT ELEMENTS IN LEXICOGRAPHICAL ORDER
OUTPUT:
Program no.25
PROGRAM TO REVERSE A STRING BY PASSING IT TO FUNCTION
#include<stdio.h>
#include<string.h>
void Reverse(char str[]);
int main(){
char str[100];
printf("Enter a string to reverse: ");
gets(str);
Reverse(str);
printf("Reversed string: ");
puts(str);
return 0;
}
void Reverse(char str[]){
int i,j;
char temp[100];
for(i=strlen(str)-1,j=0; i+1!=0; --i,++j)
{
temp[j]=str[i];
}
temp[j]='\0';
strcpy(str,temp);
}
OUTPUT:
Program no.26
PROGRAM FOR FINDING THE SUM OF ARRAY ELEMENT USING
POINTER
#include<stdio.h>
#include<conio.h>
void main() {
int numArray[10];
int i, sum = 0;
int *ptr;
printf("\nEnter 10 elements : ");
for (i = 0; i < 10; i++)
scanf("%d", &numArray[i]);
ptr = numArray; /* a=&a[0] */
for (i = 0; i < 10; i++) {
sum = sum + *ptr;
ptr++;
}
printf("The sum of array elements : %d", sum);
}
OUTPUT:
Program no.27
PROGRAM FOR FINDING THE LENGTH OF STRING USING POINTER
OUTPUT:
Program no.28
PROGRAM TO SWAP NUMBERS IN CYCLIC ORDER USING CALL BY
REFERENCE
OUTPUT:
Program no.29
CREATE A STRUCTURE TO STORE THE INFORMATION OF STUDENTS
#include<stdio.h>
#include<conio.h>
struct name
{
char first[50];
char middle[50];
char last[50];
};
struct dob
{
int dd;
int mm;
int yy;
};
struct mark
{
int eng;
int math;
int cs;
};
struct info
{
int serial;
char adno[50];
struct name n;
struct dob d;
struct mark m;
};
int main()
{
int j,n;
printf("enter the no of students whose data you want to sore\n");
scanf("%d",&n);
struct info in[n];
printf("enter the serial no ,admsn no,name(first,middle,last),dob,(date,month,year)&
marks(eng,math,cs) of each student\n");
for(j=0;j<n;j++)
scanf("%d%s%s%s%s%d%d%d%d%d%d",in[j].serial,&in[j].adno,&in[j].n.first,&in[j].n.
middle,&in[j].n.last,&in[j].d.dd,&in[j].d.mm,&in[j].d.yy,&in[j].m.eng,&in[j].m.math,&in[j].
m.cs);
printf("serial no ad.no,\t name \t\t dob \t eng math cs\n");
for(j=0;j<n;j++)
printf("%6d %10s%7s%7s%7s\t %2d%2d%4d \t\t%2d%2d%2d\n",
in[j].serial,in[j].adno,in[j].n.first,in[j].n.middle,in[j].n.last,in[j].d.dd,in[j].d.mm,in[j].d.yy,i
n[j].m.eng,in[j].m.math,in[j].m.cs);
return 0;
}
OUTPUT:
Program no.30
CREATE A STRUCTURE OF 10 EMPLOYEES
#include<stdio.h>
struct name
{
char first[50];
char middle[50];
char last[50];
};
struct address
{
char area[50];
char city[50];
char state[50];
};
struct employee
{
int salary;
int age;
struct name n;
struct address a;
char post[50];
};
int main()
{
int j;
struct employee e[1];
printf("enter the name(first,middle,last),address
(area,city,state),age,salary and post of 10 employees\n");
for(j=0;j<10;j++)
scanf("%s%s%s%s%s%s %d%d%s",
&e[j].n.first,&e[j].n.middle,&e[j].n.last,&e[j].a.area,&e[j].a.city,&e[j].a.state,
&e[j].age,&e[j].salary,&e[j].post);
printf("\t\tname\t\taddress\t\tage salary \t post\n");
for(j=0;j<10;j++)
{
printf("%7s%7s%7s%7s%7s%7s %2d %5d %4s\n",
e[j].n.first,e[j].n.middle,e[j].n.last,e[j].a.area,e[j].a.city,e[j].a.state,e[j].age,e[j].salar
y ,e[j].post);
}
return 0 ;
}
OUTPUT: