CPL Week2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WEEK 2 Objective: Getting familiar with how to formally describe a solution to a

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

i)Sum and Average of 3 numbers


ALGORITHM:(Leave One page space)

FLOWCHART: (Leave One page space)

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

ii) Conversion of Fahrenheit to Celsius and vice versa


Formula to Convert Temperature From Celsius To Fahrenheit
Fahrenheit = (celsius * 1.8) + 32
Formula to Convert Temperature From Fahrenheit to Celsius
Celsius = (Fahrenheit-32)/1.8;
ALGORITHM:

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:

iii) Simple interest calculation

Simple Interest is a mathematical concept. It is a kind of interest in the capital that we


get if we keep the money invested for a particular period of time. The formula for
simple interest is:

Here, SI = Simple Interest


P = Principal amount
R = Rate of interest
T = Time period of investment
ALGORITHM:

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

You might also like