J.V.M.G.R.R.
COLLEGE
CHARKHI DADRI
A
Mathematical Lab-1 Paper
Submitted in partial fulfillment
for the award of Degree of
Bachelor of Science
PRACTICAL FILE OF PROGRAMMING IN C
LANGUAGE
SESSION-2024-2025
CHAUDHARY BANSI LAL UNIVERSITY,BHIWANI,HARYANA
[J.V.M.G.R.R. COLLEGE]
CHARKHI DADRI
Supervisor Submitted by:-
Name-Anshika
Class- B.Sc.(CS)2nd year
Uni.roll.no.-231262006009
College roll.no.- 1232602012
J.V.M.G.R.R. COLLEGE
CHARKHI DADRI
A
Mathematical Lab-1 Paper
Submitted in partial fulfillment
for the award of Degree of
Bachelor of Science
PRACTICAL FILE OF PROGRAMMING IN C
LANGUAGE
SESSION-2024-2025
CHAUDHARY BANSI LAL UNIVERSITY,BHIWANI,HARYANA
[J.V.M.G.R.R. COLLEGE]
CHARKHI DADRI
Supervisor Submitted by:-
Name-Anshika
Class- B.Sc.(CS)2nd year
Uni.roll.no.-23126200600
College roll.no.- 1232602012
INDEX
Sr.no. Title Date Sign
1. Program to find sum of two numbers
2. Program to find the square of a
number
3. Program to find the area of a circle
4. Program to interchange the values of
two variables
5. Program to show the use of sqrt()
function
6. Program to find area of triangle
7. Program to calculate compound
interest
8. Program to read a number in decimal
format and print it in hexadecimal and
octal form
9. Program to check equality of two
numbers
10. Program to check equality of two
numbers
1. Program to find the sum of two numbers:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
c=a+b;
printf("Sum of two numbers is:%d",c);
getch();
}
Output:
2. Program to find the square of a number:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b;
clrscr();
printf("enter the number which you want to square:");
scanf("%d",&a);
b=a*a;
printf("the square of the number is :%d",b);
getch();
}
Output:
3. Program to find the area of a circle:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
clrscr();
printf("enter the radius of circle:");
scanf("%f",&a);
c=3.14*a*a;
printf("the area of circle is :%f",c);
getch();
}
Output:
4. Program to interchange the values of two
variables:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x,y,temp;
clrscr();
printf("Enter two numbers:");
scanf("%f%f",&x,&y);
temp=x;
x=y;
y=temp;
printf("Values of number after interchange are %f\n %f",x,y);
getch();
}
Output:
5. Program to show the use of sqrt() function:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
double x;
clrscr();
printf("Enter the number whose square root is to be found:")
scanf("%lf",&x);
printf("The square root of %lf is %lf",x,Sqrt(x));
getch();
}
Output:
6. Program to find area of triangle:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c,s,area;
clrscr();
printf("Enter the three sides of triangle:");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of triangle is:%f",area);
getch();
}
Output:
7. Program to calculate compound interest:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float principal,rate,time,n,amount,CI;
clrscr();
printf("Enter the principal:\n");
scanf("%f",&principal);
printf("Enter the rate:\n");
scanf("%f",&rate);
printf("Enter the time period:\n");
scanf("%f",&time);
printf("The compound interest is:");
n=1+(rate/100);
amount=principal*pow(n,time);
CI=amount-principal;
printf("%f",CI);
getch();
}
Output:
8. Program to read a number in decimal
format and print it in hexadecimal and
octal form:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x;
clrscr();
printf("Enter the decimal numbers\n");
scanf("%d",&x);
printf("Number in octal representation is %0\n",x);
printf("Number in hexadecimal form is %x\n",x);
getch();
}
Output:
9. Program to check equality of two
numbers:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b;
clrscr();
printf("Enter the values of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
if(a==b)
{
printf("ais equal to b");
}
else
{
printf("a is not equal to b");
}
getch();
}
Output:
10. Program to testing a leap year:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int year;
clrscr();
printf("Please enter an year:");
scanf("%d",&year);
if(year%4==0&&100!=0||year%400==0)
{
printf("%d is a leap year ",year);
}
else
{
printf("%dis not a leap year",year);
}
printf("\nleap year is tested");
getch();
}
Output-1:
Output-2: