Professional Documents
Culture Documents
Week 1:: Write Simple Programs Using Printf, Scanf Aim: To Write A Simple C Programs Using Printf, Scanf
Week 1:: Write Simple Programs Using Printf, Scanf Aim: To Write A Simple C Programs Using Printf, Scanf
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()
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
return 0;
OUTPUT
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;
}
Result
The given program executed successfully
Flow Chart:
Source code
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
scanf("%f", &fahrenheit);
Output:
Enter Fahrenheit:
100
Celsius: 37.777779
Result
The given program executed successfully
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:
Result
The given program executed successfully
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;
result=sqrt(n);
getch();
Output
Result
The given program executed successfully
Algorithm:
Step 1: Start
Step 5: Stop
Flowchart
Result
The given program executed successfully
WEEK 3 iii) Area of a triangle using heron’s formulae
Algorithm:
Step 1: Start
Step 5: Stop
Flowchart
Result
The given program executed successfully
WEEK 3 iv) 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