Week 1: Write simple programs using printf(), scanf()
Aim: To write a simple c programs using printf(), scanf()
ALGORITHM
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop
FLOWCHART
// C program to add two numbers
#include <stdio.h>
int main()
int A, B, sum = 0; // Ask user to enter the two numbers
printf("Enter two numbers A and B : \n"); // Read two numbers from the user || A = 2, B = 3
scanf("%d%d", &A, &B); // Calculate the addition of A and B // using '+' operator
sum = A + B; // Print the sum
printf("Sum of A and B is: %d", sum);
return 0;
OUTPUT
Enter two numbers A and B
Sum=10
Result
The given program executed successfully
Week 2: (i).Sum and average of 3 numbers
Aim: To write a c program to find the Sum and average of 3 numbers
Algorithm:
Step 1: Start
Step 2: Declare variables num 1, num2, num 3 and sum , average.
Step 3: Read values num1, num 2, num 3
Step 4: Add num 1, num 2, num 3 and assign the result to sum.
sum←num1+num2 +num3
Average ← sum/3
Step 5: Display sum and average
Step 6: Stop
Flow Chart:
Program:
#include<stdio.h>
int main( )
{
int a,b,c;
int sum,average;
printf("Enter any three integers: ");
scanf("%d%d %d",&a,&b,&c);
sum = a+b+c;
average=sum/3
printf("Sum and average of three integers: %d %d",sum,average);
return 0;
}
SAMPLE INPUT: Enter any three integers:2 4 5
EXPECTED OUTPUT: Sum and average of three integers: 11 3
Result
The given program executed successfully
Week 2: (ii) Conversion of Fahrenheit to Celsius and vice versa
Aim: To write a c program to find the Conversion of Fahrenheit to Celsius and vice versa
Algorithm:
Step 1: Start
Step 2: Read the value of temperature to be converted from the user
Step 3: Assign the value to a variable, say ‘cel’
Step 4: Initialize f = 0
Step 5: f = ((5/9) * cel ) + 32
Step 6: Display f
Step 7: Stop
Flow Chart:
Source code
#include<stdio.h>
#include<conio.h>
void main()
float celsius, fahrenheit;
clrscr();
printf("\n Enter Temp in Fahrenheit : ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit-32) / 1.8;
printf("\n Temperature in Celsius : %.2f ", celsius);
getch();
}
Output:
Enter Fahrenheit:
100
Celsius: 37.777779
Result
The given program executed successfully
Week 2: (iii) simple interest
Aim: To write a c program to find the simple interest calculation
Algorithm:
Step 1. Start
Step 2.Store the values of the Principal, Time, and the Rate in the particular data types.
Step 3.Now use this formula (P * R * T) / 100 to calculate the simple interest. The P is
the principal, R is the rate of interest, and the T is the total period of time.
Step 4.The calculated value from the above expression is the Simple interest.
Step 5. End
Flow Chart:
Source code
#include<iostream>
#include <stdio.h>
using namespace std;
int main()
{
//principle amount
float p = 5;
//time
float r = 4;
//rate in years
float t = 5;
// Simple interest
float SI = 0;
SI =(p * t * r) / 100;
printf("Simple Interest = %f",SI);
return 0;
}
Output:
Enter the principal amount: 7000
Enter the rate of interest: 50
Enter the time: 2
Simple Interest = 7000.000000
Amount = 14000.000000
Result
The given program executed successfully
WEEK 3 (i) Finding the square root of a given number
Aim: To write a c program to find the square root of a given number
Algorithm:
1. Start
2. Accept one number from user.
3. Use the function sqrt() to find square root.
4. Print the result.
5. End
Flow Chart:
Source code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
int n,result;
printf("Enter any number :\t");
result=sqrt(n);
printf("\nSquare root of given number is : %d",result);
getch();
Output
Enter any number
12
Square root of given number is
3.464102
Result
The given program executed successfully
WEEK 3 ii) Finding compound interest
Aim: To write a c program to find compound interest
Algorithm:
Step 1: Start
Step 2: Read 3 number for p, n, r
Step 3: Calculate C.I = p × (1 + r/100)n – p
Step 4: Print “The compound Interest = C.l”
Step 5: Stop
Flowchart
Result
The given program executed successfully
WEEK 3 iii) Area of a triangle using heron’s formulae
Aim: To write a c program to find Area of a triangle using heron’s formulae
Algorithm:
Step 1: Start
Step 2: Input the sides of the triangle.
Step3:Calculate the area of triangle using formula 12∗b∗h or sqrt((s) * (s-a) * (s-b) * (s-
c)).
Step 4. Print area of triangle.
Step 5: Stop
Flowchart
Result
The given program executed successfully
WEEK 3 iv) Distance travelled by an object
Aim: To write a c program to find Distance travelled by an object
Algorithm:
Step 1: Start
Step 2: Declare variables s , t and d.
Step 3: Take input in variable s and t from the user.
Step 4: Calculate distance by formula d = s * t
Step 5: Print distance d
Step 6: End
Flowchart
Result
The given program executed successfully