KHADIR MOHIDEEN COLLEGE
[Nationally Re-accredited with Grade ‘B’ by NAAC]
ADIRAMPATTINAM – 614 701
PG & RESEARCH DEPARTMENT OF COMPUTER SCIENCE
B. Sc. COMPUTER SCIENCE
2022 – 2023
SEMESTER – I
PROGRAMMING IN C LAB
Name: _____________________________
Reg. No. __________ Roll No. _________
KHADIR MOHIDEEN COLLEGE
[Nationally Re-accredited with Grade ‘B’ by NAAC]
ADIRAMPATTINAM – 614 701
PG & RESEARCH DEPARTMENT OF COMPUTER SCIENCE
B. Sc. COMPUTER SCIENCE
BONAFIDE CERTIFICATE
Register No: CB22S
Certified that this is a bonafide record of practical work done by Mr. /
Miss________________________________________ at Computer Science
Laboratory, Khadir Mohideen College, Adirampattinam during 2022-2023.
Staff-in-Charge Head of the Department
Submitted for the Bharathidasan University Practical Examination held on
.10.2022 at Khadir Mohideen College, Adirampattinam.
Examiners:
1.
2.
CONTENTS
S. No. Date Title of the Program Page No.
1. Centigrade to Fahrenheit Conversion
2. Odd or Even
3. Greatest of Three Numbers
4. Displaying the Week Days
5. Sum of Ten Natural Numbers
6. Matrix Multiplication
7. Finding the Maximum Number
8. Reversing a Number
9. Adding Two Numbers
10. Factorial of a Number
1. Centigrade to Fahrenheit Conversion
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
float centigrade, fahrenheit;
clrscr();
printf("\n Enter Temperature in Centigrade: ");
scanf("%f", ¢igrade);
fahrenheit = (1.8 * centigrade) + 32;
printf("\n Temperature in Fahrenheit: %f ", fahrenheit);
getch();
Output:
Enter Temperature in Centigrade: 37
Temperature in Fahrenheit: 98.599998
2. Odd or Even
Program:
#include<stdio.h>
#include<conio.h>
void main()
int num;
clrscr();
printf("Enter an integer: ");
scanf("%d", &num);
if(num%2==0)
printf("\n %d is Even.", num);
else
printf("\n %d is Odd.", num);
getch();
Output:
Enter an integer:
99
99 is Odd.
3. Greatest of Three Numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{ int a,b,c;
clrscr();
printf("Enter three numbers \n ");
scanf("%d%d%d", &a, &b, &c);
if(a>b && a>c)
printf("\n %d is the Greatest number.", a);
else if (b>c)
printf("\n %d is the Greatest number.", b);
else
printf("\n %d is the Greatest number.", c);
getch();
}
Output:
Enter three numbers
27
74
48
74 is the Greatest number.
4. Displaying the Week Days
Program:
#include<stdio.h>
#include<conio.h>
void main()
int n;
clrscr();
printf("Enter a number between 1 and 7 \n ");
scanf("%d",&n);
switch(n)
{ case 1: printf("\n Monday");
break;
case 2: printf("\n Tuesday");
break;
case 3: printf("\n Wednesday");
break;
case 4: printf("\n Thursday");
break;
case 5: printf("\n Friday");
break;
case 6: printf("\n Saturday");
break;
case 7: printf("\n Sunday");
break;
default: printf("\n enter correct choice");
getch();
Output:
Enter a number between 1 and 7
Friday
5. Sum of Ten Natural Numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
int i,sum=0;
clrscr();
printf(“Natural numbers are\n");
for(i=1;i<=10;i++)
{ printf(“%d\t”,i);
sum=sum+i;
printf(“Sum =%d”,sum);
getch();
}
Output:
Natural numbers are
1 2 3 4 5 6 7 8 9 10
Sum=55
6. Matrix Multiplication
Program:
#include<stdio.h>
#include<conio.h>
void main()
int a[10][10],b[10][10],c[10][10],n,i,j,k;
clrscr();
printf("Enter the value of N):\n ");
scanf("%d",&n);
printf("Enter the elements of Matrix A: \n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
printf("Enter the elements of Matrix B: \n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{ c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]+=a[i][k]*b[k][j];
}
printf("The product of the two matrices is: \n");
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
printf("%d\t",c[i][j]);
printf("\n");
getch();
Output:
Enter the value of N:
Enter the elements of Matrix A:
2 2
2 2
Enter the elements of Matrix B:
3 3
3 3
Product of the two matrices is:
12 12
12 12
7. Finding the Maximum Number
Program:
#include<stdio.h>
#include<conio.h>
void main()
{ int max,i,*a[5];
clrscr();
printf("Enter five element for the array: ");
for(i=0;i<5;i++)
scanf("%d",&*a[i]);
max = *a[0];
for(i=1;i<5;i++)
if(max<*a[i])
max=*a[i];
printf("Maximum number=%d",max);
getch();
}
Output:
Enter five elements for array:
2
Maximum number = 7
8. Reversing a Number
Program:
#include<stdio.h>
#include<conio.h>
void main( )
int num, rem, rev=0 ;
int *pn, *pr ;
clrscr();
printf(" Enter the number :\n ") ;
scanf("%d ",&num) ;
pn=&num ;
pr=&rev ;
do {
rem = (*pn) % 10 ;
*pr = (*pr * 10) + rem ;
*pn = (*pn) / 10 ;
} while(*pn>0) ;
printf("\n Reverse of Number is: %d ",*pr) ;
getch();
Output:
Enter the number:
1234
Reverse of Number is: 4321
9. Adding Two Numbers
Program:
#include<stdio.h>
#include<conio.h>
void main()
int num1, num2, sum;
int *ptr1, *ptr2;
clrscr();
printf("Enter two numbers: \n ");
scanf("%d%d", &num1, &num2);
ptr1 = &num1;
ptr2 = &num2;
sum = *ptr1 + *ptr2;
printf("\nSum is %d",sum);
getch();
Output:
Enter two numbers:
5 8
Sum is 13
10. Factorial of a Number
Program:
#include<stdio.h>
#include<conio.h>
long factorial(int n)
{ if (n == 0)
return 1;
else
return(n * factorial(n-1));
void main()
{ int num;
long fact;
clrscr();
printf("Enter a number: \n");
scanf("%d", &num);
fact = factorial(num);
printf("Factorial of %d is %ld\n", num, fact);
getch();
Output:
Enter a number: 6
Factorial of 6 is: 720