Raichur University Raichur
Vedanta Degree College, Raichur.
Department
Of
Computer Science
C Programming
Lab Record
Raichur University Raichur
Vedanta Degree College Raichur.
DEPARTMENT OF COMPUTER SCIENCE
CERTIFICATE
Reg. No:
This is to certify that Mr./Miss.
has satisfactorily completed the course of laboratory prescribed by the
Raichur University, Raichur for BCA I Semester, in the Laboratory of the
College during the year 2024 - 2025.
Staff Member in charge. Head of the Department
Examiners: -
1.
2.
INDEX
C Programming Assignments
Page
Sl.No Name of the program Remarks
No
1 Program to find area of circle.
2 Program to find Simple Interest.
3 Program to perform Arithmetic operations.
4 Program to find area of a triangle using three sides
5 Program to find the largest of two numbers.
Program to find the smallest of two numbers using
6
conditional operator
7 Program to perform the Sum of N natural numbers.
8 Program to perform Fibonacci Series.
9 Program to perform Factorial of a given number.
10 Program to find the given number is palindrome or not.
11 Program to find the given number is Armstrong number.
12 Program to Reverse the given number.
13 Program for Ascending order.
14 Program to find Addition of two matrixes.
15 Program to find Norm of a matrix.
16 Program to find Trace of a matrix.
17 Program to find length of the string.
18 Program to compute their sum using function addnums ()
19 Program to illustrate the function with no arguments but has
a return value.
Program to accept the roll number, name, marks obtained in
20 three tests of two students of a class and display the rollnum,
name marks and their average using STRUCT*/
/* 1. PROGRAM TO FIND THE AREA OF CIRCLE */
#include<stdio.h>
#include<conio.h>
void main()
{
float r,area;
clrscr();
printf(“ Enter the radius of the circle \n”);
scanf(“%f”,&r);
area=3.142*r*r;
printf(“ The area of a circle =%f”,area);
getch();
}
OUTPUT:
Enter the radius of the circle
5
The area of a circle= 78.549995
/*2. PROGRAM TO FIND THE SIMPLE INTEREST*/
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,si;
int t;
clrscr();
printf(“ Enter the values of p,r, and t \n”);
scanf(“%f%f%d”,&p,&r,&t);
si=(p*r*t)/100.0;
printf(“Amount=Rs. %5.2f \n”,p);
printf(“Rate=Rs. %5.2f% \n”,r);
printf(“Time=%d years \n”,t);
printf(“Simple Interest=%5.2f \n”,si);
getch();
OUTPUT:
Enter the values of p,r, and t
2000
8
3
Amount=Rs. 2000.00
Rate=Rs. 8.00%
Time=3 years
Simple Interest= 480.00
/* 3. PROGRAM TO PERFORM ARITHMATIC OPERATOR’S */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,sum,sub,mult,div,rem;
printf(“Enter the values of a & b \n”);
scanf(“%d%d”,&a,&b);
sum=a+b;
sub=a-b;
mult=a*b;
div=a/b;
rem=a%b;
printf(“The addition of two number’s is %d \n”,sum);
printf(“The subtraction of two number’s is %d \n”,sub);
printf(“The multiplication of two number’s is %d \n”,mult);
printf(“The division of two number’s is %d \n”,div);
printf(“The remainder of two number’s is %d \n”,rem);
getch();
}
OUTPUT:
Enter the values of a & b
50 5
The addition of two number’s is
55
The subtraction of two number’s is
45
The multiplication of two number’s is
250
The division of two number’s is
10
The remainder of two number’s is
0
/* 4. PROGRAM TO FIND AREA OF A TRIANGLE USING 3 SIDES */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,s;
float area;
printf(“ Enter the values \n”); scanf(“%d
%d%d”,&a,&b,&c); s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf(“ The area of triangle is= %f”,area);
getch();
}
OUTPUT:
Enter the values
2
2
2
The area of triangle is= 1.7320
/* 5. PROGRAM TO FIND THE LARGEST OF TWO NUMBERS */
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,large;
clrscr();
printf(“ Enter the two numbers \n”);
scanf(“%d%d”,&a,&b);
large=a;
if (b>large)
{
large=b;
}
printf(“Largest of two numbers =%d \n”,large);
getch();
}
OUTPUT:
Enter the two numbers
9
3
Largest of two numbers=9
/* 6. PROGRAM TO FIND THE SMALLEST OF TWO NUMBERS USING
CONDITIONAL OPERATOR*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,s;
clrscr();
printf(“ Enter the two numbers \n”);
scanf(“%d%d”,&a,&b);
s=a>b?a:b;
printf(“ The smallest of 2 number’s : %d \n”,s);
getch();
OUTPUT:
Enter the two numbers
9
5
The smallest of 2 number’s : 5
/* PROGRAM TO PERFORM THE SUM OF N NATURAL NUMBER */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum,i;
clrscr();
printf(“ Enter the value of n \n”);
scanf(“%d”,&n);
sum=0;
i=1;
do
{
sum=sum+i;
i=i+1;
}
while (i<=n);
printf(“Sum of first %d number =%d”,n,sum);
getch();
}
OUTPUT:
Enter the value of n
4
Sum of first 4 number =10
/* 8. Program to perform Fibonacci Series.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int f1=0,f2=1,f3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
printf("\n%d %d",f1,f2);
for(i=2;i<number;++i)
{
f3=f1+f2;
printf(" %d",f3);
f1=f2;
f2=f3;
}
getch();
}
Output:
Enter the number of elements:15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
/* 9. PROGRAM TO PERFORM FACTORIAL OF A GIVEN NUMBER */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,fact,i;
clrscr();
printf(“ Enter the value of n \n”);
scanf(“%d”,&n);
fact=1;
if (n==0)
{
printf(“Factorial of %d is %d”,n,fact);
}
else
{
for (i=1;i<=n;i++)
{
fact=fact*i;
}
printf(“Factorial of %d is %d”,n,fact);
}
getch();
}
OUTPUT:
Enter the value of n
4
Factorial of 4 is 24
/* 10. PROGRAM TO FIND THE GIVEN NUMBER IS PALINDROM OR NOT */
#include<stdio.h>
#include<conio.h>
void main()
{
int num,rem,sum,temp;
clrscr();
printf(“ Enter any number \n”);
scanf(“%d”,&num);
sum=0;
temp=num;
while(num>0)
{
rem = num % 10;
sum = sum * 10 + rem;
num = num /10;
}
if(tem = = sum)
{
printf(“The given number is palindrome %d”,sum);
}
else
{
printf(“The given number is not palindrome %d”,sum);
}
getch( );
}
OUTPUT:
Enter any number
121
The given number is palindrome 121
Enter any number
234
The given number is not palindrome 432
/* 11. PROGRAM TO FIND THE GIVEN NUMBER IS ARMSTRONG NUMBER. */
#include <stdio.h>
int main()
{
int num, originalNum, remainder, result = 0;
clrscr();
printf("Enter a three-digit integer: ");
scanf("%d", &num);
originalNum = num;
while (originalNum != 0)
{
// remainder contains the last digit
remainder = originalNum % 10;
result += remainder * remainder * remainder;
// removing last digit from the orignal number
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
getch();
return 0;
}
OUTPUT:
Enter a three-digit integer: 371
371 is an Armstrong number.
/* 12. PROGRAM TO REVERSE THE GIVEN NUMBER */
#include<stdio.h>
#include<conio.h>
void main()
{
long int r,rev,n;
clrscr();
printf(“ Enter any 4 digit number \n”);
scanf(“%ld”,&n);
rev=0;
while(n ! = 0)
{
r = n % 10;
rev = rev * 10 +r;
n = n/10;
}
printf(“The reverse of a given number is %ld”,rev);
getch( );
}
OUTPUT:
Enter any 4 digit number
1234
The reverse of given number is 4321
/* 13. PROGRAM FOR ASCENDING ORDER */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],I,j,t,n
clrscr();
printf(“ Input number of terms to be sorted \n”);
scanf(“%d”,&n);
printf(“ Input %d random numbers \n”,n);
for (i=1;i<=n;i++)
{
scanf(“%d”,&a[i]);
}
for (i=1;i<=n;i++)
{
for (j=1;j<=n-i;j++)
{
if (a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf(“ Sorted list in ascending order is : \n”);
for (i=1;i<=n;i++)
{
printf(“%d \n”,a[i]);
}
getch();
}
OUTPUT:
Input number of terms to be sorted
5
Input 5 random numbers
43527
Sorted list in ascending order is :
2
3
4
5
7
/* 14. PROGRAM TO FIND ADDITION OF TWO MATRIX */
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,a[10][10], b[10][10], c[10][10],m,n;
clrscr();
printf(“ \t Enter the order of matrix \t \n”);
scanf(“%d%d”,&m,&n);
printf(“ \t Enter the elements of matrix A \t \n”); for(i=0;i<m;i+
+)
for(j=0;j<n;j++)
{
scanf(“ \t %d”,&a[i][j]);
}
printf(“ \t Enter the elements of matrix B \t \n”); for(i=0;i<m;i+
+)
for(j=0;j<n;j++)
{
scanf(“ \t %d”,&b[i][j]);
}
printf(“ \t The sum of two matrices are \t \n”);
for(i=0;i<m;i++)
for(j=0;j<n;j++) c[i][j]=a[i][j]
+b[i][j]; for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf(“\t %3d”,c[i][j]);
}
getch();
}
OUTPUT:
Enter the order of matrix
22
Enter the elements of matrix A
12
22
Enter the elements of matrix B
12
22
The sum of two matrices are
24
44
/* 15. PROGRAM TO FIND NORM OF A MATRIX */
#include<stdio.h>
#include<math.h>
#include<conio.h>
main()
{
int i,j,a[10][10],m;
float norm;
clrscr();
printf(“ \t Enter the order of matrix \t \n”);
scanf(“%d”,&m);
printf(“ \t Enter the elements of matrix A \t \n”);
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
scanf(“ \t %d”,&a[i][j]);
}
}
norm=0; for(i=1;i<=m;i+
+)
{
for(j=1;j<=m;j++)
{
norm=norm+a[i][j]*a[i][j];
}
}
norm=sqrt(norm);
printf(“ The norm of given matrix is = \n”);
printf(“%f”,norm);
getch();
}
OUTPUT:
Enter the order of matrix
3
Enter the elements of matrix A
111
111
111
The norm of given matrix is =3
/* 16. PROGRAM TO FIND TRACE OF A MATRIX */
#include<stdio.h>
main()
{
int i,j,a[10][10],m,trace;
clrscr();
printf(“ \t Enter the order of matrix \t \n”);
scanf(“%d%d”,&m);
printf(“ \t Enter the elements of matrix A \t \n”);
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
scanf(“ \t %d”,&a[i][j]);
}
}
trace=0;
for(i=1;i<=m;i++)
{
trace=trace+a[i][i];
}
printf(“ The trace of given matrix is = \n”);
printf(“%d”,trace);
getch();
}
OUTPUT:
Enter the order of matrix
3
Enter the elements of matrix A
111
111
111
The trace of given matrix is =3
/* 17. PROGRAM TO FIND LENGTH OF THE STRING. */
#include <stdio.h>
int main()
{
char s[] = "Programming is funcf";
int i;
clrscr();
for(i = 0; s[i] != '\0'; ++i);
printf("Length of the string: %d", i);
getch();
return 0;
}
OUTPUT:
Length of the string: 20
/*18. PROGRAM TO COMPUTE THEIR SUM USING FUNCTION ADDNUMS ()
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,result;
clrscr();
printf("Enter the two numbers"); scanf("%d
%d",&n1,&n2); result=addnums(n1,n2);
printf("The sum of %d and %d %d\
n",n1,n2,result); getch(); `
}
int addnums(val1,val2)
int val1,val2;
{
int sum;
sum=val1+val2;
return sum;
}
OUTPUT
Enter the two numbers
12
23
The sum of 12 and 23 is=35
/* 19. PROGRAM TO ILLUSTRATE THE FUNCTION WITH NO ARGUMENTS
BUT HAS A RETURN VALUE. */
#include<stdio.h>
#include<conio.h>
void main()
{
float sum;
float total();
clrscr();
sum=total();
printf("sum=%f\n",sum);
getch();
}
float total()
{
float x,y;
x=20.0;
y=10.0;
return (x+y);
}
OUTPUT
sum=30.000000
/* 20. Program to accept the roll number, name, marks obtained in three
tests of two students of a class and display the rollnum, name marks and
their average unsing STRUCT*/
#include<stdio.h>
void main()
{
struct stud_rec
{
int Rollno;
char Name[20];
int M1;
int M2;
int M3;
float avg;
};
int i,total;
struct stud_rec student[2];
printf("Type in information of 2 students\n");
for(i=0;i<2;i++)
{
printf("Enter the rollno of student%d=\n",i+1);
scanf("%d",&student[i].Rollno);
printf("Enter the nameof the student %d=\n",i+1);
scanf("%s",student[i].Name);
printf("Enter the marks1\n");
scanf("%d",&student[i].M1);
printf("Enter the marks2\n");
scanf("%d",&student[i].M2);
printf("Enter the marks3\n");
scanf("%d",&student[i].M3);
}
printf(" \n");
printf("Rollno Name Mark1 Mark2 Mark3 Average \n"):
printf(" \n");
for(i=0;i<2;i++)
{
total=student[i].M1+student[i].M2+student[i].M3;student[i].avg=total/3.0; printf("%d%s%d%d
%d%5.2f\n",student[i].Rollno,student[i].Name,student[i].M1,stude
nt[i].M2,student[i].M3,student[i].avg);
}
printf(" \n");
getch();
}
OUTPUT
Type in information of 2 students
Enter the rollno of student 1=
1
Enter the name of the student 1=
abhi
Enter the marks1
80
Enter the marks2
90
Enter the marks3
80
Enter the rollno of student 2=
2
Enter the name of the stydent 2=
akash
Enter the marks1
70
Enter the marks2
80
Enter the marks3
60
Rno Name Mark1 Mark2 Mark3 Average
1 abhi 80 90 80 83.33
2 akash 70 80 60 70.00