c Handbook
c Handbook
No Aim
Practical Set-1 Draw a flowchart and algorithm for the
1 Find out sum of two numbers.
No. Aim
43 Write a c program to find maximum number from three
numbers using if-else ladder.
44 Write a c program to check year is leap year or not.
45 Write a c program to make calculator using menu driven
programming using switch case.
46 Write a program to find day of the week switch case.
PRACTICAL-1
Algorithm:-
Step:1 Start
Step:2 Read input a,b;
Step:3 Sum = a + b;
Step:4 Print Sum
Step:5 End
Flowchart:-
Start
Read a,b
Sum = a,b
Print Sum
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 input a=1, b=2, c=3, d=4, e=5
Step:3 Average (a,b,c,d,e)/5;
Step:4 Print Average
Step:5 End
Flowchart:-
Start
Read a,b,c,d,e
Average=(1+2+3+4+5)/5
Print Average
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 Read input Radius
Step:3 Area = 3.14 * R * R
Step:4 Print Area
Step:5 End
Flowchart:-
Start
Area = 3.14*R*R
Print Area
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 Read input a
Step:3 a = l*B
Step:4 Print a
Step:5 End
Flowchart:-
Start
a = l*b
Print a
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 Read input area
Step:3 area = l*l
Step:4 Print area
Step:5 End
Flowchart:-
Start
a = l*l
Print area
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 Read input area
Step:3 area = [(1/2)*l*b]
Step:4 Print area
Step:5 End
Flowchart:-
Start
area = [(1/2)*l*b]
Print area
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 Read input a,b,c
Step:3 if a>b and if a>c So, a is max
Step:4 if b>a and if b>c So, b is max
Step:5 if c>a and if c>b So, c is max
Step:6 print x that a or b or c is max
Step7: End
Flowchart:-
Start
Read a,b,c
TRUE FALSE
a>b
TRUE FALSE FALSE TRUE
a>c b>c
A is max B is max
C is max
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 Read input number
Step:3 if (num % 2 == 0) So, number is even
Step:4 if (num % 2 == 0) So, number is odd
Step:5 print even or odd number
Step:6 End
Flowchart:-
Start
Read num
TRUE FALSE
If num%2==0
Stop
Made by :- Hari patel C programming
Algorithm:-
Step:1 Start
Step:2 i=0
Step:3 print i
Step:4 i = i + 1
Step:5 if (i< = 5) then go to line 3;
Step:6 End
Flowchart:-
Start
Print i = 1
FALSE
If i<=5
TRUE
Print i
Stop
i=i +1
Made by :- Hari patel C programming
PRACTICAL-2
AIM:-Simple C Program
program:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“Hello World”);
getch();
}
Output:-
Hello World
Made by :- Hari patel C programming
program:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
getch();
}
Output:-
Address:- XYZ
Pin code:-384151
Made by :- Hari patel C programming
program:-
#include <conio.h>
#include <stdio.h>
void main() {
getch();
}
Output:-
Enter number of height : 3
Enter number of width : 6
******
******
******
Made by :- Hari patel C programming
PRACTICAL-3
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
int X,Y;
X=10;
Y=20;
getch();
}
Output:-
The value of X: 10
The value of Y: 20
Made by :- Hari patel C programming
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
float X,Y;
X=23.2;
Y=32.3;
getch();
}
Output:-
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
char X,Y;
X=’a’;
Y=’b’;
getch();
}
Output:-
The value of X: a
The value of Y: b
Made by :- Hari patel C programming
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
double X,Y;
X= 35.676767;
Y= 26.121212;
getch();
}
Output:-
PRACTICAL-4
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
int num1,num2,sum;
getch();
}
Output:-
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
int num1,num2,sub;
getch();
}
Output:-
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
int num1,num2,multi;
getch();
}
Output:-
program:-
#include <conio.h>
#include <stdio.h>
void main() {
clrscr();
int num1,num2,div;
getch();
}
Output:-
PRACTICAL-5
program:-
#include <stdio.h>
#include <conio.h>
void main() {
float principal, rate, time,interest;
clrscr();
printf("Enter Principal Amount (P): ");
scanf("%f", &principal);
printf("Enter Rate of Interest (R): ");
scanf("%f", &rate);
printf("Enter Time Period (N in years): ");
scanf("%f", &time);
interest = (principal * rate * time) / 100;
printf("Simple Interest (I) = %.2f\n", interest);
getch();
}
Output:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
float celsius, fahrenheit;
clrscr();
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
fahrenheit = (celsius * 9/5) +32;
printf("Temperature in Fahrenheit: %.2f\n", fahrenheit);
getch();
}
Output:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
getch();
}
Output:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, temp;
clrscr();
printf("Enter first number (a):");
scanf("%d", &a);
printf("Enter second number (b):");
scanf("%d", &b);
temp = a;
a = b;
b = temp;
printf("\n After swapping:\n");
printf("a = %d\n", a);
printf("b = %d\n", b);
getch();
}
Output:-
Enter first number (a): 5
Enter second number (b): 10
Sample Output:
Before swapping:
a=5
b = 10
After swapping:
a = 10
b=5
Made by :- Hari patel C programming
program:-
#include <stdio.h>
#include <conio.h>
void main() {
float kilometers, meters, centimeters, feet, inches;
getch();
}
Output:-
Enter distance in kilometers: 2.5
Distance in meters: 2500.00 m
Distance in centimeters: 250000.00 cm
Distance in feet: 8202.10 ft
Distance in inches: 98425.25 in
Made by :- Hari patel C programming
program:-
#include <stdio.h>
#include <conio.h>
void main() {
float radius, area;
getch();
}
Output:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
float length, breadth, area;
getch();
}
Output:-
Enter the length of the rectangle: 5
Enter the breadth of the rectangle: 3
Area of the rectangle: 15.00
Made by :- Hari patel C programming
program:-
#include <stdio.h>
#include <conio.h>
void main() {
float height, base, area;
getch();
}
Output:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, temp;
// Swapping logic
temp = a;
a = b;
b = temp;
printf("After swapping:\n");
printf("a = %d\n", a);
printf("b = %d\n", b);
getch();
}
Output:-
PRACTICAL-6
program:-
#include <stdio.h>
#include <conio.h>
void main() {
char ch;
getch();
}
Output:-
Enter a character: A
The ASCII value of 'A' is 65
Made by :- Hari patel C programming
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int day;
if (day == Sunday) {
printf("You entered: Sunday\n");
} else if (day == Monday) {
printf("You entered: Monday\n");
} else if (day == Tuesday) {
printf("You entered: Tuesday\n");
} else if (day == Wednesday) {
printf("You entered: Wednesday\n");
} else if (day == Thursday) {
printf("You entered: Thursday\n");
} else if (day == Friday) {
printf("You entered: Friday\n");
Made by :- Hari patel C programming
getch();
}
Output:-
32) Write a C program for type casting the value from integer to float
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int intValue;
float floatValue;
getch();
}
Output:-
PRACTICAL-7
AIM:-Operator
33) Write a C program to take character from user using getchar() function
and
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
char ch;
getch();
}
Output:-
Enter a character: A
You entered: 'A'
The ASCII value of 'A' is 65
Made by :- Hari patel C programming
void main() {
int a, b;
int result;
// 1. Arithmetic Operators
printf("\nArithmetic Operators:\n");
printf("a + b = %d\n", a + b);
printf("a - b = %d\n", a - b);
printf("a * b = %d\n", a * b);
printf("a / b = %d\n", a / b);
printf("a %% b = %d\n", a % b);
// 2. Assignment Operators
printf("\nAssignment Operators:\n");
Made by :- Hari patel C programming
// 3. Relational Operators
printf("\nRelational Operators:\n");
printf("a == b: %d\n", a == b);
printf("a != b: %d\n", a != b);
printf("a > b: %d\n", a > b);
printf("a < b: %d\n", a < b);
printf("a >= b: %d\n", a >= b);
printf("a <= b: %d\n", a <= b);
// 4. Logical Operators
printf("\nLogical Operators:\n");
printf("a > 0 && b > 0: %d\n", (a > 0 && b > 0));
printf("a > 0 || b > 0: %d\n", (a > 0 || b > 0));
printf("!(a == b): %d\n", !(a == b));
getch();
}
Made by :- Hari patel C programming
Output:-
Arithmetic Operators:
a + b = 15
a-b=5
a * b = 50
a/b=2
a%b=0
Assignment Operators:
result = a: 10
result += b: 15
result -= a: 5
result *= 2: 10
result /= b: 2
Relational Operators:
a == b: 0
a != b: 1
a > b: 1
a < b: 0
a >= b: 1
a <= b: 0
Logical Operators:
a > 0 && b > 0: 1
a > 0 || b > 0: 1
!(a == b): 1
Made by :- Hari patel C programming
35) Write a program to find maximum number from two numbers using
conditional operator(Ternary operator).
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int a, b, max;
getch();
}
Output:-
void main() {
int a, b;
// Initialize variables
printf("Enter an integer: ");
scanf("%d", &a);
getch();
}
Output:-
Enter an integer: 5
After Postfix Increment:
Value of a: 6
Value of b: 5 (value of a before increment)
PRACTICAL-8
void main() {
int num;
getch();
}
Output:-
Enter an integer: 4
4 is an even number.
Made by :- Hari patel C programming
void main() {
int num;
getch();
}
Output:-
Enter an integer: 7
7 is an odd number.
Made by :- Hari patel C programming
39) Write a c program to check number is positive or not using if- else
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int num;
getch();
}
Output:-
Enter an integer: 5
5 is a positive number.
Made by :- Hari patel C programming
void main() {
int num;
getch();
}
Output:-
Enter an integer: 8
8 is an even number.
Made by :- Hari patel C programming
41) Write a c program to print day according to number entered by user using
if-else ladder.
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int day;
getch();
}
Output:-
42) Write program to check weather given input is upper,lower digit and
symbol using-if else ladder
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
char ch;
getch();
}
Output:-
Enter a character: G
'G' is an uppercase letter.
Made by :- Hari patel C programming
PRACTICAL-9
void main() {
int num1, num2, num3;
getch();
}
Output:-
void main() {
int year;
getch();
}
Output:-
void main() {
char choice;
float num1, num2, result;
do {
// Display the menu
printf("\nSimple Calculator\n");
printf("1. Addition\n");
printf("2. Subtraction\n");
printf("3. Multiplication\n");
printf("4. Division\n");
printf("5. Exit\n");
printf("Enter your choice (1-5): ");
scanf(" %c", &choice);
switch (choice) {
case '1':
result = num1 + num2;
printf("Result: %.2f + %.2f = %.2f\n", num1, num2, result);
break;
case '2':
result = num1 - num2;
printf("Result: %.2f - %.2f = %.2f\n", num1, num2, result);
break;
case '3':
result = num1 * num2;
printf("Result: %.2f * %.2f = %.2f\n", num1, num2, result);
Made by :- Hari patel C programming
break;
case '4':
if (num2 != 0) {
result = num1 / num2;
printf("Result: %.2f / %.2f = %.2f\n", num1, num2, result);
} else {
printf("Error: Division by zero is not allowed.\n");
}
break;
case '5':
printf("Exiting the calculator. Goodbye!\n");
break;
default:
printf("Invalid choice! Please select a valid option.\n");
}
} while (choice != '5');
getch();
}
Output:-
Simple Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 1
Enter two numbers: 10 20
Result: 10.00 + 20.00 = 30.00
Simple Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
Enter your choice (1-5): 5
Exiting the calculator. Goodbye!
Made by :- Hari patel C programming
void main() {
int day;
printf("Day 7 is Saturday.\n");
break;
default:
printf("Invalid input! Please enter a number between 1 and 7.\
n");
break;
}
getch();
}
Output:-
47)Write a c program to print series like (1,2,3,4) (2,4,6,8) using while loop.
Ans:-
program:-
#include <stdio.h>
#include <conio.h>
void main() {
int i = 1;
printf("\n");
printf("\n");
getch();
}
Output:-
First Series: 1, 2, 3, 4
Second Series: 2, 4, 6, 8
Made by :- Hari patel C programming
void main() {
int num;
unsigned long long factorial = 1; // Use long long to handle larger factorials
getch();
}
Output:-
void main() {
int num, sum = 0;
getch();
}
Output:-
Enter a positive integer: 12345
Sum of the digits = 15
Made by :- Hari patel C programming
void main() {
int i = 1;
getch();
}
Output:-
1
2
3
4
5
6
7
8
9
10
Made by :- Hari patel C programming
void main() {
int i = 1; // Initialize counter
getch();
}
Output:-
1
2
3
4
5
6
7
8
9
10
Made by :- Hari patel C programming
void main() {
int num, sum = 0;
PRACTICAL-10
void main() {
int array[5]; // Declare an array of 5 elements
int i;
getch();
}
Made by :- Hari patel C programming
Output:-
void main() {
int array[5]; // Declare an array of 5 elements
int sum = 0; // Variable to store the sum
int i;
getch();
}
Output:-
Enter values for 5 elements:
Element 1: 10
Element 2: 20
Element 3: 30
Element 4: 40
Element 5: 50