C Programming LAB Record SEP BCA I 2024-25
C Programming LAB Record SEP BCA I 2024-25
Department
Of
Computer Science
C Programming
Lab Record
Raichur University Raichur
CERTIFICATE
Reg. No:
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 ()
#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:
#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:
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
#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:
#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:
#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:
#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:
#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:
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:
#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:
#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:
#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:
#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:
#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:
#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
#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
1 abhi 80 90 80 83.33
2 akash 70 80 60 70.00