1.
Centigrade to Fahrenheit Conversion
Aim:
To develop a C program to convert temperature from Centigrade to Fahrenheit.
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
Aim:
To develop a C program to check whether the given integer is 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
Aim:
To develop a C program to find the 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
Aim:
To develop a C program to display Monday to Sunday using switch statement
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
5
Friday
5. Sum of Ten Natural Numbers
Aim:
To develop a C Program to display first Ten Natural Numbers and their sum.
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
Aim:
To develop a C Program to perform multiplication of two matrices.
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
Aim:
To develop a C Program to find the Maximum number in an array using pointer.
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
Aim:
To develop a C Program to reverse a number using pointer.
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
Aim:
To develop a C Program to add two numbers using pointer.
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
Aim:
To develop a C Program to find the factorial of a number using recursion.
Program:
#include<stdio.h>
#include<conio.h>
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();
long factorial(int n)
{ if (n == 0)
return 1;
else
return(n * factorial(n-1));
Output:
Enter a number: 6
Factorial of 6 is: 720