EXPERIMENT – 1
AIM :- Write a program enter any two number to add using c
program with algorithm, flow chart and output.
Algorithm:-
1. Start
2. Declare variables num1, num2, and sum as integers.
3. Output "Enter first number:" and read num1 from the user.
4. Output "Enter second number:" and read num2 from the user.
5. Calculate sum as the sum of num1 and num2.
6. Output "Sum: " followed by the value of sum.
7. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
int main()
{
int num1, num2, sum;
clrscr();
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("Sum: %d\n", sum);
getch ();
}
Output:-
Enter first number: 5
Enter second number: 7
Sum: 12
EXPERIMENT – 2
Aim:- Write a program enter any two number to subtract using c
program with algorithm, flow chart and output.
Algorithm:-
1. Start
2. Declare variables num1, num2, and difference as integers.
3. Output "Enter first number:" and read num1 from the user.
4. Output "Enter second number:" and read num2 from the user.
5. Calculate difference as the result of subtracting num2 from num1.
6. Output "Difference: " followed by the value of difference.
7. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
int main()
{
int num1, num2, sub;
clrscr();
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
sub = num1 - num2;
printf("sub: %d\n", sub);
getch ();
}
Output:-
Enter first number: 10
Enter second number: 7
Sub: 3
EXPERIMENT – 3
AIM :- Write a program enter any two number to multiply using c
program with algorithm, flow chart and output.
Algorithm:-
1. Start
2. Declare variables num1, num2, and product as integers.
3. Output "Enter first number:" and read num1 from the user.
4. Output "Enter second number:" and read num2 from the user.
5. Calculate product as the result of multiplying num1 by num2.
6. Output "Product: " followed by the value of product.
7. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
int main()
{
int num1, num2, product;
clrscr();
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
sub = num1*num2;
printf("product: %d\n", product);
getch ();
}
Output:-
Enter first number: 4
Enter second number: 3
Sub: 12
EXPERIMENT – 4
AIM :- Write a program enter any two number to divide using c
program with algorithm, flow chart and output.
Algorithm:-
1. Start
2. Declare variables dividend, divisor, and quotient as integers.
3. Output "Enter dividend:" and read dividend from the user.
4. Output "Enter divisor (non-zero):" and read divisor from the user.
5. Calculate quotient as the result of dividing dividend by divisor.
6. Output "Quotient: " followed by the value of quotient.
7. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
int main()
{
int dividend, divisor, quotient;
Clrscr();
printf("Enter dividend: ");
scanf("%d", ÷nd);
printf("Enter divisor (non-zero): ");
scanf("%d", &divisor);
quotient = dividend / divisor;
printf("Quotient: %d\n", quotient);
getch ();
}
Output:-
Enter dividend: 15
Enter divisor (non-zero): 3
Quotient: 5
EXPERIMENT – 5
AIM :- Write a program enter to enter principal amount ,rate and
time then display simple interest using c program with algorithm,
flow chart and output .
Algorithm:-
1. Start
2. Declare variables principal, rate, time, and simpleInterest as floats.
3. Output "Enter principal amount:" and read principal from the user.
4. Output "Enter rate of interest:" and read rate from the user.
5. Output "Enter time (in years):" and read time from the user.
6. Calculate simpleInterest using the formula (principal * rate * time)
/ 100.
7. Output "Simple Interest: simpleInterest".
8. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
int main()
{
float principal, rate, time, simpleInterest;
clrscr();
printf("Enter principal amount: ");
scanf("%f", &principal);
printf("Enter rate of interest: ");
scanf("%f", &rate);
printf("Enter time (in years): ");
scanf("%f", &time);
simpleInterest = (principal * rate * time) / 100;
printf("Simple Interest: %.2f\n", simpleInterest);
getch ();
}
Output:-
Enter principal amount: 5000
Enter rate of interest: 2.5
Enter time (in years): 3
Simple Interest: 375.00
EXPERIMENT – 6
AIM :- Write a program enter any number then display even
number or odd number using if , else statement in c program with
algorithm, flow chart and output .
Algorithm:
1. Start
2. Declare a variable number.
3. Output "Enter a number:" and read number from the user.
4. Check if number % 2 == 0.
• If true, output "number is an even number."
• If false, output "number is an odd number."
5. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int number;
clrscr();
printf("Enter a number: ");
scanf("%d", &number);
if (number % 2 == 0)
{
printf("%d is an even number.\n", number);
}
else
{
printf("%d is an odd number.\n", number);
}
getch ();
}
Output:-
Enter a number: 7
7 is an odd number.
Enter a number: 4
4 is an even number.
EXPERIMENT – 7
AIM :- Write a program to find the largest number of the three
using c program with algorithm, flow chart and output .
Algorithm:-
1. Start
2. Declare variables num1, num2, num3, and largest as integers.
3. Output "Enter three numbers:" and read num1, num2, and num3
from the user.
4. Set largest to num1.
5. If num2 is greater than largest, update largest to num2.
6. If num3 is greater than largest, update largest to num3.
7. Output "The largest number is: largest".
8. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main() {
int num1, num2, num3;
clrscr();
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
int largest = num1;
if (num2 > largest)
{
largest = num2;
}
if (num3 > largest)
{
largest = num3;
}
printf("The largest number is: %d\n", largest);
getch ();
}
Output:-
Enter three numbers: 15 7 22
The largest number is: 22
EXPERIMENT – 8
AIM :- Write a program enter any number then display it's
multiplication table using while loop in c program with algorithm,
flow chart and output .
Algorithm:-
1. Start
2. Declare variables num and i as integers.
3. Output "Enter a number:" and read num from the user.
4. Initialize i to 1.
5. While i is less than or equal to 10:
• Output the multiplication table entry: "num x i = num * i".
• Increment i by 1.
6. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int num, i;
clrscr();
printf("Enter a number: ");
scanf("%d", &num);
i = 1;
while (i <= 10)
{
printf("%d x %d = %d\n", num, i, num * i);
i++;
}
getch ();
}
Output:-
Enter a number: 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
EXPERIMENT – 9
AIM :- Write a program to print square (*) using c program with
algorithm, flow chart and output .
Algorithm:-
1. Start
2. Declare variables sideLength, i, and j as integers.
3. Output "Enter the side length of the square:" and read sideLength from
the user.
4. Use nested loops to iterate over each row (i) and column (j) of the
square:
• Inner loop prints asterisks (*).
• After each row, move to the next line.
5. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int sideLength, i, j;
clrscr();
printf("Enter the side length of the square: ");
scanf("%d", &sideLength);
for (i = 0; i < sideLength; i++)
{
for (j = 0; j < sideLength; j++)
{
printf("* ");
}
printf("\n");
}
getch ();
}
Output:-
Enter the side length of the square: 4
* * * *
* * * *
* * * *
* * * *
EXPERIMENT – 10
AIM :- Write a program to enter any number then check it is
eligible for vote or not using c program with algorithm, flow chart
and output .
Algorithm:-
1. Start
2. Declare variable age as an integer.
3. Output "Enter your age:" and read age from the user.
4. Check if age is greater than or equal to 18:
• If true, output "You are eligible to vote."
• If false, output "You are not eligible to vote."
5. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int age;
clrscr();
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18)
{
printf("You are eligible to vote.\n");
} else
{
printf("You are not eligible to vote.\n");
}
getch ();
}
Output:-
Enter your age: 22
You are eligible to vote.
Enter your age: 16
You are not eligible to vote.
EXPERIMENT – 11
AIM :- Write a program to enter five subject marks then find total
percentage and grade using nested if statement in c program with
algorithm, flow chart and output .
Algorithm:-
1. Start
2. Declare an array subject Marks to store marks for five subjects.
3. Declare variables total Marks, percentage, and grade.
4. Input marks for each subject using a loop and calculate the total Marks.
5. Calculate the percentage by dividing the total Marks by the maximum
possible marks (5 subjects, each out of 100).
6. Determine the grade using nested if statements based on the
percentage.
7. Output total marks, percentage, and grade.
8. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int subjectMarks[5];
float totalMarks = 0, percentage;
char grade;
clrscr();
printf("Enter marks for five subjects:\n");
for (int i = 0; i < 5; i++)
{
printf("Enter marks for Subject %d: ", i + 1);
scanf("%d", &subjectMarks[i]);
totalMarks += subjectMarks[i];
}
percentage = (totalMarks / (5 * 100)) * 100;
if (percentage >= 90)
{
grade = 'A';
} else if (percentage >= 80)
{
grade = 'B';
} else if (percentage >= 70)
{
grade = 'C';
} else if (percentage >= 60)
{
grade = 'D';
} else
{
grade = 'F';
}
printf("\nTotal Marks: %.2f\n", totalMarks);
printf("Percentage: %.2f%%\n", percentage);
printf("Grade: %c\n", grade);
getch ();
}
Output:-
Enter marks for five subjects:
Enter marks for Subject 1: 85
Enter marks for Subject 2: 92
Enter marks for Subject 3: 78
Enter marks for Subject 4: 64
Enter marks for Subject 5: 95
Total Marks: 414.00
Percentage: 82.80%
Grade: B
EXPERIMENT – 12
AIM :- Write a program to enter a side of square and triangle then
find perimeter and area using c program with algorithm, flow chart
and output .
Algorithm:-
1. Start
2. Declare variables side Square, side Triangle, area Square, area
Triangle, perimeter Square, and perimeter Triangle as floats.
3. Output "Enter the side length of the square:" and read side Square from
the user.
4. Output "Enter the side length of the equilateral triangle:" and read side
Triangle from the user.
5. Calculate area Square and perimeter Square for the square.
6. Calculate area Triangle and perimeter Triangle for the equilateral
triangle.
7. Output the results for both the square and the equilateral triangle.
8. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <math.h>
int main()
{
float sideSquare, sideTriangle, areaSquare, areaTriangle,
perimeterSquare, perimeterTriangle;
printf("Enter the side length of the square: ");
scanf("%f", &sideSquare);
printf("Enter the side length of the equilateral triangle:
");
scanf("%f", &sideTriangle);
areaSquare = sideSquare * sideSquare;
perimeterSquare = 4 * sideSquare;
areaTriangle = (sqrt(3) / 4) * sideTriangle * sideTriangle;
perimeterTriangle = 3 * sideTriangle;
printf("\nSquare:\n");
printf("Area: %.2f\n", areaSquare);
printf("Perimeter: %.2f\n", perimeterSquare);
printf("\nEquilateral Triangle:\n");
printf("Area: %.2f\n", areaTriangle);
printf("Perimeter: %.2f\n", perimeterTriangle);
getch();
}
Output:-
Enter the side length of the square: 5
Enter the side length of the equilateral triangle: 4
Square:
Area: 25.00
Perimeter: 20.00
Equilateral Triangle:
Area: 6.93Perimeter: 12.00
EXPERIMENT – 13
AIM :- Write a program to enter any number then find factorial
using c program with algorithm, flow chart and output .
Algorithm:-
1. Start
2. Declare variables number and factorial.
3. Output "Enter a number:" and read number from the user.
4. Check if number is negative:
• If true, output "Factorial is not defined for negative numbers."
• If false, continue to the next step.
5. Calculate factorial using a loop.
6. Output "Factorial of number = factorial."
7. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
int number;
long long factorial = 1;
clrscr();
printf("Enter a number: ");
scanf("%d", &number);
if (number < 0)
{
printf("Factorial is not defined for negative
numbers.\n");
}
else
{
for (int i = 1; i <= number; ++i)
{
factorial *= i;
}
printf("Factorial of %d = %lld\n", number,factorial);
}
getch();
}
Output:-
Enter a number: 5
Factorial of 5 = 120
EXPERIMENT – 14
AIM :- Write a program to enter any number then find prime
number using c program with algorithm, flow chart and output.
Algorithm:-
1. Start
2. Declare a function isPrime that takes an integer parameter number and
returns a boolean.
3. If number is less than or equal to 1, return false.
4. Use a loop to check for divisors from 2 to the square root of number.
• If number is divisible by i, return false.
5. If no divisors are found, return true.
6. In the main function, declare a variable number.
7. Output "Enter a number:" and read number from the user.
8. Call the isPrime function and output the result.
9. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <stdbool.h>
bool isPrime(int number)
{
if (number <= 1)
{
return false;
}
for (int i = 2; i * i <= number; ++i)
{
if (number % i == 0)
{
return false;
}
}
return true;
}
int main()
{
int number;
clrscr();
printf("Enter a number: ");
scanf("%d", &number);
if (isPrime(number))
{
printf("%d is a prime number.\n", number);
}
else
{
printf("%d is not a prime number.\n", number);
}
getch();
}
Output:-
Enter a number: 17
17 is a prime number.
EXPERIMENT – 15
AIM :- Write a program to find Fibonacci series using c program
with algorithm, flow chart and output .
Algorithm:-
1. Start
2. Declare a function generateFibonacci that takes an integer parameter n
and prints the Fibonacci series up to n terms.
3. Declare variables first, second, and next.
4. Output "Fibonacci Series up to n terms:".
5. Use a loop to generate and print the Fibonacci series.
6. In the main function, declare a variable terms.
7. Output "Enter the number of terms for the Fibonacci series:" and read
terms from the user.
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void generateFibonacci(int n)
{
int first = 0, second = 1, next;
clrscr();
printf("Fibonacci Series up to %d terms:\n", n);
for (int i = 0; i < n; i++) {
printf("%d, ", first);
next = first + second;
first = second;
second = next;
}
printf("\n");
}
int main() {
int terms;
printf("Enter the number of terms for the Fibonacci series:
");
scanf("%d", &terms);
if (terms < 0) {
printf("Number of terms should be non-negative.\n");
} else {
generateFibonacci(terms);
}
getch();
}
Output:-
Enter the number of terms for the Fibonacci series: 10
Fibonacci Series up to 10 terms:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
EXPERIMENT – 16
AIM :- Write a program of bit wise operator using c program with
algorithm, flow chart and output .
Algorithm:-
1. Start
2. Declare a function bitwiseOperatorsDemo that takes two integers a and b
and demonstrates various bitwise operators.
3. In the function, display the results of bitwise AND (&), bitwise OR (|),
bitwise XOR (^), bitwise NOT (~), left shift (<<), and right shift (>>).
4. In the main function, declare variables operand1 and operand2.
5. Input values for operand1 and operand2 from the user.
6. Call bitwiseOperatorsDemo with the input values.
7. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void bitwiseOperatorsDemo(int a, int b)
{
printf("Bitwise AND (&): %d & %d = %d\n", a, b, a & b);
printf("Bitwise OR (|): %d | %d = %d\n", a, b, a | b);
printf("Bitwise XOR (^): %d ^ %d = %d\n", a, b, a ^ b);
printf("Bitwise NOT (~): ~%d = %d\n", a, ~a);
printf("Left Shift (<<): %d << 1 = %d\n", a, a << 1);
printf("Right Shift (>>): %d >> 1 = %d\n", a, a >> 1);
}
int main() {
int operand1, operand2;
clrscr();
printf("Enter two integers: ");
scanf("%d %d", &operand1, &operand2);
bitwiseOperatorsDemo(operand1, operand2);
getch();
}
Output:-
Enter two integers: 5 3
Bitwise AND (&): 5 & 3 = 1
Bitwise OR (|): 5 | 3 = 7
Bitwise XOR (^): 5 ^ 3 = 6
Bitwise NOT (~): ~5 = -6
Left Shift (<<): 5 << 1 = 10
Right Shift (>>): 5 >> 1 = 2
EXPERIMENT – 17
AIM :- Write a program of ASCII using c program with algorithm,
flow chart and output .
Algorithm:-
1. Start
2. Declare a character variable inputChar.
3. Output "Enter a character:" and read inputChar from the user.
4. Display the ASCII value of inputChar.
5. Display characters and their ASCII values for the range [65, 90].
6. End
Flowchart:-
PROGRAM:
#include <stdio.h>
#include <conio.h>
void main()
{
char inputChar;
clrscr();
printf("Enter a character: ");
scanf(" %c", &inputChar);
printf("ASCII value of %c: %d\n", inputChar, inputChar);
printf("\nASCII values for characters in the range [65,
90]:\n");
for (int i = 65; i <= 90; ++i)
{
printf("Character: %c, ASCII value: %d\n", i, i);
}
getch();
}
Output:-
Enter a character: A
ASCII value of A: 65
ASCII values for characters in the range [65, 90]:
Character: A, ASCII value: 65
Character: B, ASCII value: 66
Character: C, ASCII value: 67
...
Character: Y, ASCII value: 89
Character: Z, ASCII value: 90