Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ex1 Simple Computational Problems Sample

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

1.

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.

2. Uppercase to Lower case


Aim:
Write a C Program to convert uppercase character to lowercase character
using ASCII code.
Algorithm:
Step 1: Start the Program
Step 2: Include header files
Step 3: Declare two character variables upr, lwr
Step 4: Declare integer variable ascii
Step 5: Enter upper case value at Runtime
Step 6: Calculate ascii=upr+32
Step 7: Print the lower case value (ascii)
Step 8: Repeat the process for lower case to Upper case
Step 9: Stop the Program.
FlowChart:

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

// convert in upper case


printf (" \n Enter the Lower Case Character: ");
scanf (" %c", &lwr);
ascii = lwr - 32;
printf (" %c character in the Upper case is: %c", lwr, ascii);

return 0;
}

Output:

Result:
Thus the above program has been executed successfully.

3. Square of Ascii value of a given character

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 1: Start the Program

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.

Step 4: Print the resultant variable i.e SI.

Step 5: Stop the Program.

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.

5. Sum of Any Two Numbers' Squares


Aim:

Write a C Program to to find and print the sum of the square of the given two
numbers.

Algorithm:

Step 1: Start the Program


Step 2: Include header files
Step 3: Declare the integer variable num1, num2, sqr1, sqr2, sum
Step 4: Enter Any two numbers at Runtime
Step 5: Square the numbers and store the values in sqr1,sqr2
Step 6: Add the two value and store values into sum
Step 7: Print the Value sum
Step 8: Stop the Program.
Flowchart:

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:

Thus the above program has been executed successfully.


6. Area & Perimeter of Rectangle
Aim:
Write a C program to calculate area and perimeter of Rectangle
Algorithm:

Program:

#include<stdio.h>

int main()

int l, b, area, peri;

printf("Enter the length and the breadth\n");

scanf("%d%d", &l, &b);

area = l * b;

peri = 2 * (l + b);

printf("The area is %d\n", area);

printf("The perimeter is %d\n", peri);


return 0;

Output:

Result:

Thus the above program has been executed successfully.

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.

/* C Program to Calculate Gross Salary of an Employee */

#include <stdio.h>

int main()
{
char name[60];
float basic_salary, hra_per, da_per, HRA, DA, Gross_Salary;

printf("Enter the Basic Salary of an Employee: ");


scanf("%f", &basic_salary);

printf("Enter the HRA Percentage of an Employee: ");


scanf("%f", &hra_per);

printf("Enter the DA Percentage of an Employee: ");


scanf("%f", &da_per);

HRA = basic_salary * (hra_per /100);


DA = basic_salary * (da_per / 100);

Gross_Salary = basic_salary + HRA + DA;


printf("\nBasic Salary = %.2f \nHRA Amount = %.2f \nDA Amount = %.2f
\nGross Salary = %.2f", basic_salary, HRA, DA, Gross_Salary);

return 0;
}

Output:

You might also like