/* 1. Program to calculate the addition of two number using function */
#include<stdio.h>
main()
{
int n1,n2,result;
clrscr();
printf(" Enter the two number \n");
scanf("%d%d",&n1,&n2);
result=addnum(n1,n2);
printf(" The addition of two number is =%d ",result);
getch();
}
/* Function declaration */
int addnum(a,b)
int a,b;
{
int sum;
sum=a+b;
return(sum);
}
***************OUTPUT***************************
Enter the two number
50
50
The addition of two number is =100
/* 2. Program to calculate the division of two number using function */
#include<stdio.h>
main()
{
int n1,n2,result;
clrscr();
printf(" Enter the two number \n");
scanf("%d%d",&n1,&n2);
result=divnum(n1,n2);
printf(" The division of two number is =%d ",result);
getch();
}
/* Function declaration */
int divnum(a,b)
int a,b;
{
int div;
div=a/b;
return(div);
}
***************OUTPUT***************************
Enter the two number
100
2
The division of two number is =50
/* 3. Program to calculate the multiplication of two number using function */
#include<stdio.h>
main()
{
int n1,n2,result;
clrscr();
printf(" Enter the two number \n");
scanf("%d%d",&n1,&n2);
result=mulnum(n1,n2);
printf(" The multiplication of two number is =%d ",result);
getch();
}
/* Function declaration */
int mulnum(a,b)
int a,b;
{
int mul;
mul=a*b;
return(mul);
}
***************OUTPUT***************************
Enter the two number
12
12
The multiplication of two number is =144
/* 4. Program to find the GCD & LCM of two number using function*/
#include<stdio.h>
main()
{
int n1,n2,lcm,gcd;
clrscr();
printf(" Enter the two integer numbers\n");
scanf("%d%d",&n1,&n2);
gcd=gcd1(n1,n2);
lcm=(n1*n2)/gcd;
printf(" The GCD number is %d \n",gcd);
printf("The LCM number is =%d \n ",lcm);
getch();
}
/*function declaration */
int gcd1(int a, int b)
{
int num,den,rem;
if(a>=b)
{
num=a;
den=b;
}
else
{
num=b;
den=a;
}
rem=num%den;
while(rem!=0)
{
num=den;
den=rem;
rem=num%den;
}
return(den);
}
***************OUTPUT***************************
Enter the two integer numbers
20
25
The GCD number is 5
The LCM number is =100
/* 5. Program to find the given year is leap or not using function */
#include<stdio.h>
main()
{
int year;
clrscr();
printf(" Enter the year\n");
scanf("%d",&year);
leapyear(year);
getch();
}
leapyear(int year)
{
if(year%4==0)
printf("The given year %d is a leap year ",year);
else
printf("The given year %d is not a leap year" ,year);
}
***************OUTPUT***************************
Enter the year
2004
The given year 2004 is a leap year
Enter the year
2010
The given year 2010 is not a leap year
/* 6. Program to find the factorial of given numbers using Recursive
function*/
#include<stdio.h>
main()
{
int n,f;
clrscr();
printf("Enter the number \n");
scanf("%d",&n);
f=fact(n);
printf("The factorial is = %d \n ",f);
getch();
}
int fact(x)
int x;
{
int f;
if(x= =0)
return(1);
else
f=x*fact(x-1);
return(f);
}
***************OUTPUT***************************
Enter the number
4
The factorial is = 24
Enter the number
0
The factorial is = 1
/* 7. Program to sort an array using function */
#include<stdio.h>
#include<conio.h>
main()
{
int i;
static int marks[5]={35,20,60,10,90};
clrscr();
printf(" Marks before sorting \n");
for(i=0;i<5;i++)
printf("%4d",marks[i]);
printf("\n");
sort(5,marks);
printf("Marks after sorting \n");
for(i=0;i<5;i++)
printf("%4d",marks[i]);
getch();
}
sort(m,x)
int m,x[];
{
int i,j,t;
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
if(x[j-1]>=x[j])
{
t=x[j-1];
x[j-1]=x[j];
x[j]=t;
}
}
***************OUTPUT***************************
Marks before sorting
35 20 60 10 90
Marks after sorting
10 20 35 60 90
/* 8. Program to illustrate passing of the entire array as an argument*/
#include<stdio.h>
#include<conio.h>
main()
{
int i, a[6];
clrscr();
printf("Enter array element \n");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
arraypass(a);
}
int i;
arraypass(int a1[])
{
printf("The entered array element is \n");
for(i=0;i<5;i++)
{
printf("%d\n",a1[i]);
}
getch();
}
***************OUTPUT***************************
Enter array element
1
2
3
4
5
The entered array element is
1
2
3
4
5
/* 9.Program to illustrate the comparision of two variable using structure */
#include<stdio.h>
struct class
{
int n;
char name[10];
float marks;
};
main()
{
int x;
struct class student1={1,"Preeti",78.9};
struct class student2={2,"Anand",74.33};
struct class student3;
student3=student2;
clrscr();
x=(student3.n==student2.n)&&(student3.marks == student2.marks)?1:0;
if(x==1)
{
printf("\n student2 & student3 are same \n");
│printf("Rollno\tNmae\tMarks\n");
printf("%d\t%s\t%f\t",student3.n,student3.name,student3.marks);
}
else
{
printf("\n student2 & student 3 are different \n");
│printf("Rollno\tNmae\tMarks\n");
printf("%d\t%s\t%f\t",student1.n,student1.name,student1.marks);
}
getch();
}
***************OUTPUT***************************
student2 & student3 are same
Rollno Nmae Marks
2
Anand 74.330002
/* 10. Program to find the average marks of student obtained in
Three subject using structure */
#include<stdio.h>
main()
{
struct stdent
{
int rollno,m1,m2,m3;
char name[20];
float avg;
}st[20];
int i,total,n;
clrscr();
printf("Enter the no of student information \n");
scanf("%d",&n);
printf("Enter %d students information \n",n);
for(i=0;i<n;i++)
{
printf("Student %ds information is ",i+1);
printf("\n----------------------------------\n");
printf("Rollno:=");
scanf("%d",&st[i].rollno);
printf("Name:=");
scanf("%s",&st[i].name);
printf("Subject1 marks :=");
scanf("%d",&st[i].m1);
printf("Subject2 marks:");
scanf("%d",&st[i].m2);
printf("Subject3 marks:=");
scanf("%d",&st[i].m3);
}
printf("******************************************************
**\n");
printf("Rollno\tName\tMarks1\tMarks2\tMarks3\tTotal\tAverage\n");
printf("******************************************************
**\n");
for(i=0;i<n;i++)
{
total=st[i].m1+st[i].m2+st[i].m3;
st[i].avg=total/3;
printf("%d\t%s\t%d\t%d\t%d\t%d\t%f\n",st[i].rollno,st[i].name,st[i].m1,st[i].m2,st[i].m,
total,st[i].avg);
}
printf("******************************************************
*\n");
getch();
}
***************OUTPUT***************************
Enter the no of student information
2
Enter 2 students information
Student 1s information is
---------------------------------Rollno:=1
Name:=Preeti
Subject1 marks :=90
Subject2 marks:90
Subject3 marks:=90
Student 2s information is
---------------------------------Rollno:=2
Name:=Anand
Subject1 marks :=90
Subject2 marks:90
Subject3 marks:=90
********************************************************
Rollno Name Marks1 Marks2 Marks3 Total Average
********************************************************
1
Preeti 90
90 90 270 90.000000
2
Anand 90 90
90 270 90.000000
*******************************************************
/* 11. Program to illustrate Union */
#include<stdio.h>
main()
{
union number
{
int n1;
float n2;
};
union number x;
clrscr();
printf("Enter the value of n1 \n");
scanf("%d",&x.n1);
printf("Enter the value of n2 \n");
scanf("%f",&x.n2);
printf("\n n1=%d",x.n1);
printf("\n n2=%f",x.n2);
getch();
}
***************OUTPUT***************************
Enter the value of n1
40
Enter the value of n2
70
n1=0
n2=70.000000
/* 12. Program to swap two number using pointer */
#include<stdio.h>
main()
{
int n1,n2;
clrscr();
printf("Enter the two number \n");
scanf("%d%d", &n1,&n2);
printf("Before swap n1=%d and n2=%d \n",n1,n2);
swap(&n1,&n2);
printf("After the swap n1=%d and n2=%d \n",n1,n2);
}
int swap(int *k1 ,int *k2)
{
int t;
t=*k1;
*k1=*k2;
*k2=t;
}
***************OUTPUT***************************
Enter the two number
60
100
Before swap n1=60 and n2=100
After the swap n1=100 and n2=60
/* 13.Program to Access a varible using pointer */
#include<stdio.h>
main()
{
int x,y;
int *ptr;
x=10;
ptr=&x;
y=*ptr;
clrscr();
printf(" The value of x is %d \n\n",x);
printf("%d is stored at address %u \n",x,&x);
printf("%d is stored at address %u \n",*&x,&x);
printf("%d is stored address %u \n ",*ptr,ptr);
printf("%d is stored at address %u \n",y,*&ptr);
printf("%d is stored at address %u \n ", y,&y);
getch();
}
***************OUTPUT***************************
The value of x is 10
10 is stored at address 65490
10 is stored at address 65490
10 is stored address 65490
10 is stored at address 65490
10 is stored at address 65492
/* 14. Program to illustrate a Macro substitution */
#include<stdio.h>
#define PI 3.142
main()
{
float area;
int r;
printf("Enter the radius \n");
scanf("%d",&r);
area= r*r*PI;
printf(" Area of circle is %f \n",area);
getch();
}
***************OUTPUT***************************
Enter the radius
2
Area of circle is 12.586
/* 15. Program to find the largest of three numbers using Macro */
#include<stdio.h>
#define large(x,y)((x>y)?x:y)
main()
{
int a,b,c,lar;
clrscr();
printf(" Enter the three number \n");
scanf("%d%d%d",&a,&b,&c);
lar=large(a,large(b,c));
printf(" The largest values is %d",lar);
getch();
}
***************OUTPUT***************************
Enter the three number
20
40
70
The largest values is 70
/* 16.Program illustrate the macros with arguments */
#include<stdio.h>
#define sqr(x) (x*x)
main()
{
float p,sqr1;
clrscr();
printf(" Enter the value of p\n");
scanf("%f",&p);
sqr1=sqr(p);
printf(" square number is =%2.0f\n", sqr1);
getch();
}
***************OUTPUT***************************
Enter the value of p
12
Square number is =144
Enter the value of p
16
Square number is =256
/* 17. Program to find the largest of two number using function */
#include<stdio.h>
main()
{
int a,b;
clrscr();
printf("Enter the two numbers \n");
scanf("%d%d",&a,&b);
large(a,b);
}
/* function to compute the largest */
large( x,y)
int x,y;
{
if(x>y)
printf("tThe largest value is %d\n",x);
else
printf("The largest value is %d\n",y);
}
***************OUTPUT***************************
Enter the two numbers
40
80
The largest value is 80
Enter the two numbers
90
100
The largest value is 100
/* 18.Program to determines whether it is an alphabet,a digit or a special symbol */
#include<stdio.h>
main()
{
char ch,ct;
char char_is();
clrscr();
printf("Enter a character \n");
ch=getchar();
ct=char_is(ch);
if(ct=='A')
printf("It is a alphabet \n ");
else if(ct=='D')
printf("It is a digit \n");
else if(ct=='X')
printf("It is a special symbol \n");
}
char char_is(cyar)
char cyar;
{
if((cyar>='a'&& cyar<='z')||(cyar>='A' && cyar<='Z'))
return('A');
else if(cyar>='0'&& cyar<='9')
return('D');
else
return('X');
}
***************OUTPUT***************************
Enter a character
r
It is a alphabet
Enter a character
9
It is a digit
Enter a character
*
It is a special symbol
/* 19. Program to compute the area of triangle */
#include<stdio.h>
#include<math.h>
main()
{
float s1,s2,s3,area;
float tri_area();
clrscr();
printf("Enter the thre sides of a triangle \n");
scanf("%f%f%f",&s1,&s2,&s3);
area=tri_area(s1,s2,s3);
printf("The area of the triangle =%f\n",area);
}
float tri_area(a,b,c)
float a,b,c;
{
float s,area;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
return(area);
}
***************OUTPUT***************************
Enter the thre sides of a triangle
3
4
5
The area of the triangle =6.000000
/* 20. Program writing to and reading from a file */
#include<stdio.h>
main()
{
FILE *f1;
char c;
clrscr();
printf("Data input \n");
f1=fopen("input","w");
while((c=getchar())!=EOF)
putc(c,f1);
fclose(f1);
printf("Data output \n");
f1=fopen("input","r");
while((c=getc(f1))!=EOF)
printf("%c",c);
fclose(f1);
}
***************OUTPUT***************************
Data input
This is file handling program
^Z
Data output
This is file handling program
INDEX
C PROGRAMS
SLNO NAME OF THE PROGRAM
1
Program to calculate the addition of two
number using function
2
Program to calculate the division of two
number using function
3
Program to calculate the multiplication of
two number using function
4
Program to find the GCD & LCM of two
number using function
5
Program to find the given year is leap or
not using function
6
Program to find the factorial of given
numbers using Recursive function
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Program to sort an array using function
Program to illustrate passing of the entire
array as an argument
program to illustrate the comparison of
two variable using structure
Program to find the average marks of
student obtained in three subject using
structure
Program to illustrate Union
Program to swap two number using
pointer
Program to Access a variable using pointer
Program to illustrate a Macro substitution
Program to find the largest of three
numbers using Macro
Program illustrate the macros with
arguments
Program to find the largest of two number
using function
Program to determines whether it is an
alphabet digit or a special symbol
Program to compute the area of triangle
Program writing to and reading from a file
PAGE NO REMARKS
© Copyright 2026 Paperzz