Ex1 Simple Computational Problems Sample
Ex1 Simple Computational Problems Sample
Ex1 Simple Computational Problems Sample
Fahrenheit to Celsius
Aim:
Write a C program to convert Fahrenheit to Celsius using C Formula.
Algorithm:
Step 1: Start the Program.
Step 2: Declare two variables farh, cels
Step 3: Enter Fahrenheit value at run time
Step 4: Apply formula to convert Fahrenheit to Celsius
Cels=(farh-32)*5/9;
Step 5: Print cels.
Step 6: Stop the Program.
Flowchart:
Program:
#include<stdio.h>
int main(){
float fahrenheit, celsius;
printf("Enter Fahrenheit:");
scanf("%f",&fahrenheit);
celsius = (fahrenheit - 32)*5/9;
printf("Celsius: %f", celsius);
return 0;
}
Output:
Result:
Thus the above program has been executed successfully.
Program:
#include <stdio.h>
#include <conio.h>
int main ()
{
char upr, lwr; // declare variables
int ascii;
// convert in lower case
printf (" Enter the Upper Case Character: ");
scanf (" %c", &upr);
ascii = upr + 32;
printf (" %c character in Lower case is: %c", upr, ascii);
return 0;
}
Output:
Result:
Thus the above program has been executed successfully.
Aim:
Write a C Program to find the Square of ASCII of a given character.
Algorithm:
Step 1: Start the Program
Step 2: Include header files
Step 3: Declare the character Variable ch
Step 4: Declare integer variable asci
Step 5: Enter Any character at Runtime
Step 6: Calculate Square of Ascii value(ascii=ch*ch)
Step 7: Print the Value ascii
Step 8: Stop the Program.
Flowchart:
Program:
#include <stdio.h>
#include <math.h>
int main ()
{
char ch;
int ascii;
printf("Enter Any Character:");
scanf("%c",&ch);
ascii=ch*ch;
printf("Square of %c is %d",ch,ascii);
return 0;
}
Output:
Result:
Thus the above program has been executed successfully.
4. Simple Interest Calculation
Aim:
Write a C program to get the principal amount, number of years, rate of interest from
the user and print the simple interest for the same.
Algorithm:
Step 2: Input three integers and store them in three variables one by one. Let us say the
variables are P, R, and N.
Step 3: Now, multiply the three variables i.e. PNR and divide this whole result by 100 and
store it in a variable say SI.
Flowchart:
Program:
# include <stdio.h>
int main(){
//Simple interset program
int P, R, T;
double SI;
printf("Enter the principal: ");
scanf("%d", &P);
printf("Enter the rate of interest: ");
scanf("%d", &R);
printf("Enter the no of Years: ");
scanf("%d", &T);
SI = (P * R * T) / 100;
printf("The Simple interest is %.2f", SI);
return 0;
}
Output:
Result:
Thus the simple interest calculation program has been executed successfully.
Write a C Program to to find and print the sum of the square of the given two
numbers.
Algorithm:
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int num1, num2, sqr1, sqr2, sum;
printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
sqr1 = num1*num1;
sqr2 = num2*num2;
sum = sqr1 + sqr2;
printf("Sum of their square = %d", sum);
return 0;
}
Output:
Result:
Program:
#include<stdio.h>
int main()
area = l * b;
peri = 2 * (l + b);
Output:
Result:
Hard:
7. Given the values of the variables X,Y and Z write a program to rotate
their values such that X has the value of Y,Y has the value of Z and Z
has the value of X.
Program:
#include<stdio.h>
int main()
{
int x,y,z,temp;
printf("Enter the value of x,y,z\n");
scanf("%d %d %d",&x,&y,&z);
temp=x;
x=y;
y=z;
z=temp;
printf("x=%d y=%d z=%d",x,y,z);
return 0;
}
Output:
8.writea program that reads a floating-point number and then displays
right-most digit of the integral part of the number.
Program:
#include<stdio.h>
void main()
{
int ip,rmd;
float fval;
printf("\n\n\tEnter is value::");
scanf("%f",&fval);
ip=fval;
rmd=ip%10;
printf("\n right most of ::%d is rmd::%d\n\n",ip,rmd);
Output:
9. Writeprogram to read a four digit integer and print the sum of its
digit. Hints: Use / and % operators.
Program:
#include<stdio.h>
int main()
{
int num,a,b,c,d,x,y,result;
printf("Enter a number");
scanf("%d",&num);
a=num%10;
x=num/10;
b=x%10;
y=x/10;
c=y%10;
d=y/10;
result=a+b+c+d;
printf("%d",result);
return 0;
}
Output:
10. Given three values, write a program to read three values from
keyboard and print out the largest of them without using if statement.
#include<stdio.h>
int main()
{
int x,y,z,a,b;
printf("Enter the value of x,y,z\n");
scanf("%d%d%d",&x,&y,&z);
printf("largest\n");
a=(x>y)?x:y;
b=(a>z)?a:z;
printf("%d",b);
return 0;
}
Output:
11.
#include <stdio.h>
int main()
{
char name[60];
float basic_salary, hra_per, da_per, HRA, DA, Gross_Salary;
return 0;
}
Output: