You are on page 1of 5

Ex.

No:4

C PROGRAMMING USING SIMPLE STATEMENTS AND EXPRESSION

4.1 program to convert celsius to fahrenheit


AIM:

To convert the temperature input given in Celsius to Fahrenheit unit.


ALGORITHM:

Step 1:
Step 2:
Step 3:
Step 4:
Step 5:

Start.
Read the Input cl (i.e) temperature in Celsius.
Convert the Celsius value to Fahrenheit value by using the
calculation fh=(1.8 * cl) + 32.
Print the output fh (i.e) the equivalent Fahrenheit value
Stop.

PROGRAM:

#include<stdio.h>
#include<conio.h>
int main()
{
float fh,cl;
clrscr();
printf("enter temperature value in Celsius:");
scanf("%f",&cl);
fh=(1.8 * cl)+32;
printf("converted Fahrenheit value :%f", fh);
getch();
return 0;
}
OUTPUT:

enter the temperature in Celsius :35


converted Fahrenheit value : 95.000000

4.2 To Find Whether The Given Number Is Even Or Odd


AIM:

To find whether the given number is an odd number or an even number.


ALGORITHM:

Step 1:
Step 2:
Step 3:
Step 4:

Start.
Read the number n
Check the condition if(n%2) ==0, if the condition is true
Step3.1 : print The number is even
Step3.2 : print The number is odd
Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(Enter the Number:);
scanf(%d,&n);
if(n%2==0)
printf(\n The number is even );
else
printf(\n The number is Odd);
getch();
}
OUTPUT:
Enter the Number
6
The number is even
Enter the Number
87
The number is odd

4.3 Greatest Of Three Numbers


AIM:

To find the greatest of three numbers.


ALGORITHM:

Step 1:
Step 2:
Step 3:

Start.
Read three numbers a,b,c
Check the condition if (a>b && a>c), if the condition is true
Step 3.1: print a is the greatest number

Step 4:

Else, check the condition if (b>a && b>c), if the condition is true

Step 5:

Step 4.1: print b is the greatest number


Step 4.2: Else, print c is the greatest number
Stop.

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(%d is the greatest,a);
else if(b>a && b>c)
printf(%d is the greatest,b);
else
printf(%d is the greatest,c);
getch();
}
OUTPUT:
Enter three numbers
58
60
40
60 is the greatest

4.4 Armstrong Number of three digits

AIM:

To find the whether given three digit number is amstrong or not

ALGORITHM:

Step 1:
Step 2:
Step 3:

Start.
Read the variable number.
Assign the variable number to originalNumber.

Step 4:

Set a while loop using condition (originalNumber != 0), if the


condition true
4.1 remainder = originalNumber%10;
4.2 result += remainder*remainder*remainder;
4.3 originalNumber /= 10;
Check condition if(result == number) if the
condition true
5.1 Print given number is an Armstrong number
5.1 Else Print given number is not an Armstrong number

Step 5:

Step 6:

End

PROGRAM:

#include <stdio.h>
int main()
{
int number, originalNumber, remainder, result = 0;
printf("Enter a three digit integer: ");
scanf("%d", &number);
originalNumber = number;

while (originalNumber != 0)
{
remainder = originalNumber%10;
result += remainder*remainder*remainder;
originalNumber /= 10;
}
if(result == number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);
return 0;
}
OUTPUT:

Enter a three digit integer: 371


371 is an Armstrong number.

You might also like