0% found this document useful (0 votes)
26 views

I Bcom Ca C PRG

Uploaded by

Sathya Ashok
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

I Bcom Ca C PRG

Uploaded by

Sathya Ashok
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

BON SECOURS ARTS AND SCIENCE COLLEGE FOR WOMEN

(AFFILIATED TO PERIYAR UNIVERSITY, SALEM )


GOPALAPURAM, SOWTHAPURAM (PO),
NAMAKKAL (DT), TAMIL NADU.

DEPARTMENT OF COMMERCE (COMPUTER APPLICATION)


DEPARTMENT OF COMMERCE

RECORD NOTEBOOK
PRACTICAL – C PROGRAMMING LAB

SUBJECT CODE: 23UCCEP01 SEMESTER: I

YEAR: 2024-2025
BON SECOURS ARTS AND SCIENCE COLLEGE FOR WOMEN
(Affiliated to Periyar University, Salem – 11)

NAMAKKAL – 638 008.

DEPARTMENT OF COMMERCE (COMPUTER APPLICATION)


PRACTICAL RECORD NOTEBOOK

Register Number : -------------------------------------------------

Name of the student : -------------------------------------------------

Subject Code : 23UCCEP01

Subject Title : PRACTICAL –C PROGRAMMING LAB

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 ……………….

Subject In-charge Head of the Department

Internal Examiner External Examiner


INDEX

S.N PAG
O DATE TOPICS E NO SIGN

1 ROOTS OF QUADRATIC EQUATION


2/7/2024

2 TOTAL & SUM OF INDIVIDUAL DIGITS


9/7/2024

16/7/202 FIBONACCI SEQUENCE OF n


3
4 NUMBERS

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

COUNT OF LINES, WORDS AND


8
3/9/2024 CHARACTERS IN A TEXT

13/9/202
9 PRIME NUMBER
4

24/9/202 FACTORIAL USING RECURSIVE


10
4 FUNCTION

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

Enter the coeff of x (b): 6

Enter the constant value (c): 8

The roots -2.00 and -4.00 are real and different.


_______________________________________

Enter the coeff of x^2 (a): 1

Enter the coeff of x (b): 4

Enter the constant value (c): 5

The roots -2.00+1.00i and -2.00-1.00i are real and different.


_________________________________________________

Enter the coeff of x^2 (a): 1

Enter the coeff of x (b): 2

Enter the constant value (c): 1

The roots -1.00 and -1.00 are real and equal.

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

Total number of digits is: 4


Sum of digits is: 26

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

Fibonacci series for 10 numbers:


0 1 1 2 3 5 8 13 21 34

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);
}

double sum_series(double x, int n) {


double sum = 0;
int i,sign = 1;

for (i = 0; i <= n; i++) {


sum += sign * pow(x, i) / facto(i);
sign = -sign;
}
return sum;
}

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;

printf("Enter a string: ");


scanf("%s", s);

l = strlen(s);

for (i = 0; i < l / 2; i++) {


if (s[i] != s[l - i - 1]) {
f = 1;
break;
}
}

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");

while ((ch = getchar()) != EOF) {


c++;

if (ch == '\n')
{
l++;
w++;
}
else if (ch == ' ' || ch == '\t') {
w++;
}
}

printf("Lines: %d\nWords: %d\nCharacters: %d\n", l, w, (c-l));

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);

printf("Enter the end value: ");


scanf("%d", &e);

printf("\n Prime numbers are:\n\t");


for(i=s;i<=e;i++)
if (isprime(i))
printf("%d \t", i);

return 0;
}

Sample output:
Enter the start value: 30
Enter the end value: 70

Prime numbers are:


31 37 41 43 47 53 59 61 67

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;
};

char calculategrade(float marks) {


if (marks >= 80)
return 'A';
else if (marks >= 60)
return 'B';
else if (marks >= 50)
return 'C';
else if (marks >= 40)
return 'D';
else
return 'E';
}

void output(struct student s)


{ printf("\nRoll number \tName \tMarks \tGrade");
printf("\n***************************************\n");
printf(" \t%d \t%s \t%.2f \t%c", s.rollNo,s.name,s.marks,s.grade);
}

int main() {
int n, i, r;
printf("Enter the number of students: ");
scanf("%d", &n);

struct student st[n];

for (i = 0; i < n; i++) {


printf("Enter details of student %d\n", i + 1);
printf("Roll Number: ");
scanf("%d", &st[i].rollNo);
printf("Name: ");
scanf("%s", st[i].name);
printf("Marks: ");
scanf("%f", &st[i].marks);
st[i].grade = calculategrade(st[i].marks);
}
printf("Enter the roll number of the student to print details: ");
scanf("%d", &r);
for (i = 0; i < n; i++) {
if (st[i].rollNo == r)
{
output(st[i]);
break;
}
}
if (i == n) {
printf("Student with roll number %d not found.\n", r);
}

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

Roll number Name Marks Grade


********************************
* 102 benny 99.00 A *
********************************

Result:
Thus, the above program has been executed and verified successfully.

You might also like