I Bcom Ca C PRG
I Bcom Ca C PRG
RECORD NOTEBOOK
PRACTICAL – C PROGRAMMING LAB
YEAR: 2024-2025
BON SECOURS ARTS AND SCIENCE COLLEGE FOR WOMEN
(Affiliated to Periyar University, Salem – 11)
BONAFIDE CERTIFICATE
This is to certify that the bonafide record of practical work done in the
Computer Laboratory of Bon Secours Arts and Science College for Women, during the
Academic Year 2024-2025 is submitted for Periyar University Practical Examination held
on ……………….
S.N PAG
O DATE TOPICS E NO SIGN
23/7/202
4 SUM OF SERIES
4
5 BUBBLE SORT
6/8/2024
20/8/202
6 MATRIX MULTIPLICATION
4
29/8/202
7 PALINDROME
4
13/9/202
9 PRIME NUMBER
4
27/9/202
11 STUDENTS MARK & GRADE DETAILS
4
Coding:
#include<stdio.h>
#include<math.h>
#include<complex.h>
int main()
{
double a,b,c,d,r1,r2;
printf("\n Enter the coeff of x^2 (a): ");
scanf("%lf",&a);
printf("\n Enter the coeff of x (b): ");
scanf("%lf",&b);
printf("\n Enter the constant value (c): ");
scanf("%lf",&c);
d=b*b-4*a*c;
if(d>0)
{
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
printf("\n The roots %.2f and %.2f are real and different. \n",r1,r2);
}
else if(d<0)
{
r1=-b/(2*a);
r2=sqrt(-d)/(2*a);
printf("\n The roots %.2f+%.2fi and %.2f-%.2fi are real and different. \n",r1,r2,r1,r2);
}
else
{
r1=r2=-b/2*a;
printf("\n The roots %.2f and %.2f are real and equal. \n",r1,r2);
}
return 0;
}
Sample output:
Enter the coeff of x^2 (a): 1
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include<stdio.h>
int main()
{
int n,r,c=0,s=0;
printf("\n Enter a number: ");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
s+=r;
n=n/10;
c++;
}
printf("\n Total number of digits is: %d .\n Sum of digits is: %d\n",c,s);
return 0;
}
Sample output:
Enter a number: 5678
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include<stdio.h>
int main()
{
int i,n,a=-1,b=1,c;
printf("\n Enter a number: ");
scanf("%d",&n);
printf("\n Fibonacci series for %d numbers: \n\t",n);
for(i=1;i<=n;i++)
{
c=a+b;
a=b;
b=c;
printf("%d\t",c);
}
return 0;
}
Sample output:
Enter a number: 10
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
#include <math.h>
double facto(int n) {
if (n == 0 || n == 1) return 1;
return n * facto(n - 1);
}
int main() {
double x;
int n;
printf("Enter the value of x: ");
scanf("%lf", &x);
printf("Enter the number of terms (n): ");
scanf("%d", &n);
double result = sum_series(x, n);
printf("The sum of the series is: %lf\n", result);
return 0;
}
Sample output:
Enter the value of x: 1
Enter the number of terms (n): 10
The sum of the series is: 0.367879
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include<stdio.h>
int main()
{
int a[10],i,j,t,n;
printf("\n Enter the max no.of Elements to Sort: \n");
scanf("%d",&n);
printf("\n Enter %d Elements : \n",n);
for(i=0; i<n; i++)
{ scanf("%d",&a[i]); }
printf("\n Elements after sorting \n");
printf("\n************************\n");
for(i=0; i<n; i++)
for(j=i+1; j<n; j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
for(i=0; i<n; i++)
{ printf("%d\t",a[i]); }
return 0;
}
Sample output:
Enter the max no.of Elements to Sort:
7
Enter 7 Elements :
89 56 43 7 12 -3 5
Elements after sorting
************************
-3 5 7 12 43 56 89
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
int main()
{
int r1, c1, r2, c2,i,j,k;
printf("Enter the number of rows and columns of the first matrix: ");
scanf("%d %d", &r1, &c1);
printf("Enter the number of rows and columns of the second matrix: ");
scanf("%d %d", &r2, &c2);
if (c1 != r2)
{ printf("Matrix multiplication is not possible.\n");
return 1;
}
int m1[r1][c1], m2[r2][c2], r[r1][c2];
printf("Enter elements of the first matrix:\n");
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
printf("Element [%d][%d]: ", i, j);
scanf("%d", &m1[i][j]);
}
}
printf("Enter elements of the second matrix:\n");
for (i = 0; i < r2; i++)
{
for (j = 0; j < c2; j++)
{
printf("Element [%d][%d]: ", i, j);
scanf("%d", &m2[i][j]);
}
}
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
r[i][j] = 0;
}
}
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
for (k = 0; k < c1; k++)
{
r[i][j] += m1[i][k] * m2[k][j];
}
}
}
printf("Resultant matrix after multiplication:\n");
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
printf("%d ", r[i][j]);
}
printf("\n");
}
return 0;
}
Sample output:
Enter the number of rows and columns of the first matrix: 2 2
Enter the number of rows and columns of the second matrix: 2 2
Enter elements of the first matrix:
Element [0][0]: 2
Element [0][1]: 2
Element [1][0]: 2
Element [1][1]: 2
Enter elements of the second matrix:
Element [0][0]: 3
Element [0][1]: 3
Element [1][0]: 3
Element [1][1]: 3
Resultant matrix after multiplication:
12 12
12 12
___________________________________________________________
Enter the number of rows and columns of the first matrix: 1 2
Enter the number of rows and columns of the second matrix: 3 4
Matrix multiplication is not possible.
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
#include <string.h>
int main() {
char s[100];
int i, l;
int f = 0;
l = strlen(s);
if (f) {
printf("%s is not a palindrome\n", s);
} else {
printf("%s is a palindrome\n", s);
}
return 0;
}
Sample output:
Enter a string: radio
radio is not a palindrome
_____________________________________
Enter a string: radar
radar is a palindrome
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
int main() {
int l = 0, w = 0, c = 0;
char ch;
printf("Enter your text & finally press ctrl + Z \n");
if (ch == '\n')
{
l++;
w++;
}
else if (ch == ' ' || ch == '\t') {
w++;
}
}
return 0;
}
Sample output:
Enter your text & finally press ctrl + Z
hi welcome!!!
this is multi lines,
words and
character count.
^Z
Lines: 4
Words: 10
Characters: 58
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
int isprime(int n)
{ int i;
if (n <= 1)
return 0;
for (i = 2; i < n; i++)
{
if (n % i == 0) return 0;
}
return 1;
}
int main()
{
int i,s,e;
printf("Enter the start value: ");
scanf("%d", &s);
return 0;
}
Sample output:
Enter the start value: 30
Enter the end value: 70
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
int facto(int n)
{
if (n == 0 || n == 1)
{ return 1; }
else
{ return n * facto(n - 1); }
}
int main()
{
int n;
printf("Enter a number to find its factorial: ");
scanf("%d", &n);
printf("Factorial of %d is %d\n", n, facto(n));
return 0;
}
Sample output:
Enter a number to find its factorial: 10
Factorial of 10 is 3628800
Result:
Thus, the above program has been executed and verified successfully.
Coding:
#include <stdio.h>
struct student {
int rollNo;
char name[50];
float marks;
char grade;
};
int main() {
int n, i, r;
printf("Enter the number of students: ");
scanf("%d", &n);
return 0;
}
Sample output:
Enter the number of students: 3
Enter details of student 1
Roll Number: 101
Name: moni
Marks: 78
Enter details of student 2
Roll Number: 102
Name: benny
Marks: 99
Enter details of student 3
Roll Number: 103
Name: vino
Marks: 100
Enter the roll number of the student to print details: 102
Result:
Thus, the above program has been executed and verified successfully.