CPL Week2
CPL Week2
CPL Week2
problem in a series of finite steps both using textual notation and graphic notation.
Suggested Experiments /Activities:
Tutorial 2: Problem-solving using Algorithms and Flow charts.
Lab 1: Converting algorithms/flow charts into C Source code. Developing the
algorithms/flowcharts for the following sample programs
i) Sum and average of 3 numbers
ii) Conversion of Fahrenheit to Celsius and vice versa
iii) Simple interest calculation
SOURCE CODE:
#include <stdio.h>
int main()
{
int a, b, c, sum;
float avg;
printf("Enter 3 numbers: \n");
scanf("%d %d %d", &a, &b, &c);
sum = a + b + c;
avg = sum / 3;
printf("Sum = %d \n", sum);
printf("Average = %.2f", avg);
return 0;
}
OUTPUT:(Don’t write this output in your Observation Book-This is only for your
information..How to write the output)
Enter 3 numbers:
234
Sum = 9
Average = 3.00
FLOWCHART:
SOURCE CODE:
#include<stdio.h>
int main()
{
float celsius,fahrenheit;
printf("\nEnter Temp in Fahrenheit : ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit-32) / 1.8;
printf("\n Temperature in Celsius : %.2f ", celsius);
return 0;
}
OUTPUT: (Don’t write this output in your Observation Book-This is only for your
information..How to write the output)
Enter Temp in Fahrenheit : 35.6
Temperature in Celsius : 2.00
ALGORITHM:
FLOWCHART:
SOURCE CODE:
#include<stdio.h>
int main()
{
float celsius, fahrenheit;
printf("\n Enter Temp in Celsius : ");
scanf("%f", &celsius);
fahrenheit = (1.8 * celsius) + 32;
printf("\n Temperature in Fahrenheit : %.2f ", fahrenheit);
return 0;
}
OUTPUT:
FLOWCHART:
SOURCE CODE:
# include <stdio.h>
int main()
{
float P, R, T;
double SI;
printf("Enter the Principal Amount: ");
scanf("%f", &P);
printf("Enter the rate of interest: ");
scanf("%f", &R);
printf("Enter the time period: ");
scanf("%f", &T);
SI = (P * T * R) / 100;
printf("The Simple interest is %f", SI);
return 0;
}
OUTPUT: (Don’t write this output in your Observation Book-This is only for your
information..How to write the output)
Enter the Principal Amount: 10000
Enter the rate of interest: 2.3
Enter the time period: 4
The Simple interest is 920.000000