0% found this document useful (0 votes)
17 views

Lab Record Download

The document describes a C program to calculate the area of different geometric shapes like circle, rectangle, and triangle by providing a menu-driven option to the user. It includes the sample input-output, source code logic and explanation, and test case results.

Uploaded by

fijetew677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lab Record Download

The document describes a C program to calculate the area of different geometric shapes like circle, rectangle, and triangle by providing a menu-driven option to the user. It includes the sample input-output, source code logic and explanation, and test case results.

Uploaded by

fijetew677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Exp.

Name: Write a C program to compute the Area


S.No: 1 Date: 2023-10-24
of the various Geometrical Shapes

Aim:

Page No: 1
Write a program in C which is a menu-driven program to compute the area of the various geometrical shapes.

Sample Input and Output:

ID: 23911A1268
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice : 2
Enter length and width : 2.34 2.45
Area of rectangle : 5.733000
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice : 1
Enter radius : 3.67

2023-2027-IT-B
Area of circle : 42.292347
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice : 3

Vidya Jyothi Institute of Technology (Autonomous)


Enter base and height : 5.78 4.67
Area of triangle : 13.496301
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice : 4

Source Code:

areaofGeometricalShape.c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main() {
int choice;

Page No: 2
do{
printf("1. Area of circle\n2. Area of rectangle\n3. Area of triangle\n4. Exit\n");
printf("Enter your choice : ");
scanf("%d" ,&choice);
switch(choice)

ID: 23911A1268
{
case 1: {
float radius,area;
printf("Enter radius : ");
scanf("%f",&radius);
area= (float)radius*radius*3.14;
printf("Area of circle : %f\n", area);
break;
}

case 2: {
float length,width,area;

2023-2027-IT-B
printf("Enter length and width : ");
scanf("%f%f",&length,&width);
area=(float)length*width;
printf("Area of rectangle : %f\n",area);
break;
}

Vidya Jyothi Institute of Technology (Autonomous)


case 3: {
float base,height,area;
printf("Enter base and height : ");
scanf("%f%f",&base,&height);
area=(float)0.5*base*height;
printf("Area of triangle : %f\n",area);
break;
}
case 4: {
exit(1);

}
}while(choice!=4);
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
2
Enter length and width :

Page No: 3
2.34 2.45
Area of rectangle : 5.733000
1. Area of circle
2. Area of rectangle

ID: 23911A1268
3. Area of triangle
4. Exit
Enter your choice :
1
Enter radius :
3.67
Area of circle : 42.292347
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit

2023-2027-IT-B
Enter your choice :
3
Enter base and height :
5.78 4.67
Area of triangle : 13.496301

Vidya Jyothi Institute of Technology (Autonomous)


1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
4

Test Case - 2

User Output
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
3
Enter base and height :
23.45 34.56
Area of triangle : 405.216034
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
4

Test Case - 3

User Output

Page No: 4
1. Area of circle
2. Area of rectangle
3. Area of triangle

ID: 23911A1268
4. Exit
Enter your choice :
1
Enter radius :
3.498
Area of circle : 38.421051
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :

2023-2027-IT-B
2
Enter length and width :
54.61 48.69
Area of rectangle : 2658.960938
1. Area of circle
2. Area of rectangle

Vidya Jyothi Institute of Technology (Autonomous)


3. Area of triangle
4. Exit
Enter your choice :
4

Test Case - 4

User Output
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
2
Enter length and width :
45 67
Area of rectangle : 3015.000000
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
3
Enter base and height :
98 48
Area of triangle : 2352.000000
1. Area of circle
2. Area of rectangle

Page No: 5
3. Area of triangle
4. Exit
Enter your choice :
4

ID: 23911A1268
Test Case - 5

User Output
1. Area of circle
2. Area of rectangle
3. Area of triangle
4. Exit
Enter your choice :
2

2023-2027-IT-B
Enter length and width :
12.12 13.13
Area of rectangle : 159.135605
1. Area of circle
2. Area of rectangle
3. Area of triangle

Vidya Jyothi Institute of Technology (Autonomous)


4. Exit
Enter your choice :
4
Exp. Name: Write a program to calculate Simple
S.No: 2 Date: 2023-10-25
interest and Compound interest

Aim:

Page No: 6
Write a program to calculate the simple interest and compound interest by reading principal amount, rate
of interest and time.

Note: Use the printf() function and ensure that the character '\n' is printed at the end of the result.

ID: 23911A1268
The formula to find simple interest is simpleInterest = (principal * rate * time) / 100 .

The formula to find compound interest is


compoundInterest = principal * pow(1 + (rate / 100), time) - principal .

Note: Use float data type for all the involved variables.
Source Code:

Program315.c
#include <stdio.h>

2023-2027-IT-B
#include <math.h>
int main(){
float P,R,T,SI,CI;
printf("Enter P,R,T: ");
scanf("%f%f%f",&P,&R,&T);
SI= (P * R * T)/100;

Vidya Jyothi Institute of Technology (Autonomous)


CI= P * ((pow((1 + R/ 100), T))) -P;
printf("SI= %f\nCI= %f\n",SI,CI);

return 0;

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter P,R,T:
5000 7 5
SI= 1750.000000
CI= 2012.760376

Test Case - 2

User Output
Enter P,R,T:
1000 6 4
CI= 262.476685
SI= 240.000000

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 7
S.No: 3 Exp. Name: Program to swap given two numbers Date: 2023-10-31

Aim:
Write a C Program to swap given two numbers.

Page No: 8
Logic : By using a temporary variable temp
temp — a,
a — b,
b — temp.

ID: 23911A1268
Source Code:

temp.c

#include <stdio.h>
int main(){
int x,y,temp,b;
printf("Enter the values of x and y: ");
scanf("%d%d",&x,&y);
printf("Before swapping x = %d, y = %d\n",x,y);
temp = x;
x = y;

2023-2027-IT-B
y = temp;
b = y;
printf("After swapping x = %d, b = %d\n",x,b);
return 0;
}

Vidya Jyothi Institute of Technology (Autonomous)


Execution Results - All test cases have succeeded!
Test Case - 1

User Output
Enter the values of x and y:
10 20
Before swapping x = 10, y = 20
After swapping x = 20, b = 10

Test Case - 2

User Output
Enter the values of x and y:
247 692
Before swapping x = 247, y = 692
After swapping x = 692, b = 247
Exp. Name: Write a C program to Swap Two
S.No: 4 Date: 2023-10-26
numbers with out using a Third variable

Aim:

Page No: 9
Write a program to swap two integer values without using a third variable.

Note: Use the printf() function with a newline character (\n) at the end.
Source Code:

ID: 23911A1268
Program311.c

#include <stdio.h>
int main(){
int a,b,temp;
printf("Enter two integers: ");
scanf("%d%d",&a,&b);
printf("Before swapping a = %d, b = %d\n",a,b);
temp = a;
a = b;
b = temp;
printf("After swapping a = %d, b = %d\n",a,b);

2023-2027-IT-B
return 0;
}

Execution Results - All test cases have succeeded!

Vidya Jyothi Institute of Technology (Autonomous)


Test Case - 1

User Output
Enter two integers:
23 67
Before swapping a = 23, b = 67
After swapping a = 67, b = 23

Test Case - 2

User Output
Enter two integers:
99 89
Before swapping a = 99, b = 89
After swapping a = 89, b = 99
Exp. Name: Program to check whether a given
S.No: 5 Date: 2023-10-26
number is even or odd.

Aim:

Page No: 10
Write a C program to check whether a given number is EVEN or ODD.

ALGORITHM:

Step 1: Start

ID: 23911A1268
Step 2: Input num1
Step 3: Check if(num1 is divisible by 2) then
Step 3.1: Print "number is even"
else
Step 3.2: Print "number is odd"
Step 4: Stop
Source Code:

evenOrOdd.c
#include <stdio.h>
int main()

2023-2027-IT-B
{
int n;
printf("Enter a number to check: ");
scanf("%d",&n);
if ( n % 2 == 0){
printf("%d is even\n",n);
}

Vidya Jyothi Institute of Technology (Autonomous)


else{
printf("%d is odd\n",n);
}
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter a number to check:
30
30 is even

Test Case - 2

User Output
Enter a number to check:
47
47 is odd
Exp. Name: Write a C program to find Sum of n
S.No: 6 Natural numbers and Sum of Squares of n Natural Date: 2023-11-10
numbers

Page No: 11
Aim:
Write a C program to find the sum of n natural numbers and sum of squares of n natural numbers.

During execution, the program should print the following message on the console:

ID: 23911A1268
n :

For example, if the user gives the input as:

n : 5

Then the program should print the result as:

sum : 15
sum of squares : 55

Note: Use the printf() function with a newline character ( \n ) at the end.

2023-2027-IT-B
Source Code:

SumAndSumOfSquares.c

#include <stdio.h>

Vidya Jyothi Institute of Technology (Autonomous)


int main() {
int n,sum=0,i;
printf("n : ");
scanf("%d",&n);
for
(i=1;i<=n;i++)
(sum += i);
printf("sum : %d\n",sum);
sum = 0;
for
(i=1;i<=n;i++)
sum += i*i;

printf("sum of squares : %d\n",sum);


return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
n :
3
sum : 6
sum of squares : 14

Test Case - 2

User Output

Page No: 12
n :
5
sum : 15
sum of squares : 55

ID: 23911A1268
Test Case - 3

User Output
n :
10
sum : 55
sum of squares : 385

2023-2027-IT-B
Test Case - 4

User Output
n :
15
sum : 120

Vidya Jyothi Institute of Technology (Autonomous)


sum of squares : 1240
Exp. Name: Checking whether a number is divisible
S.No: 7 Date: 2023-11-10
by any given number

Aim:

Page No: 13
Write a program to check whether a number is divisible by any given number.
Input format:
• The first line of input should be the number (dividend)
• The second line of input should contain the divisor
Output format:

ID: 23911A1268
• If the number is divisible then print "divisible"
• if the number is not divisible then print "not divisible"
• if the divisor is zero then print "infinity"
Source Code:

division.c

#include <stdio.h>
int main()
{
int n,m;
scanf("%d",&n);

2023-2027-IT-B
scanf("%d",&m);
if(m!=0 && n%m == 0)
{
printf("divisible\n");
}
else if (m!=0 && n%m !=0)
{

Vidya Jyothi Institute of Technology (Autonomous)


printf("not divisible\n");
}
else
printf("infinity\n");
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
4
2
divisible

Test Case - 2

User Output
7
2
not divisible
Exp. Name: C program to evaluate the arithmetic
S.No: 8 Date: 2023-11-11
expression

Aim:

Page No: 14
Write a C program to evaluate the arithmetic expression ((a - (((b / c) * d) + e)) * (f + g)). Read the values a, b, c,
d, e, f, g from the standard input device.
Source Code:

expression.c

ID: 23911A1268
#include <stdio.h>
int main()
{
int a,b,c,d,e,f,g,AP;
printf("enter value of a : ",a);
scanf("%d",&a);
printf("enter value of b : ",b);
scanf("%d",&b);
printf("enter value of c : ",c);
scanf("%d",&c);
printf("enter value of d : ",d);

2023-2027-IT-B
scanf("%d",&d);
printf("enter value of e : ",e);
scanf("%d",&e);
printf("enter value of f : ",f);
scanf("%d",&f);
printf("enter value of g : ",g);

Vidya Jyothi Institute of Technology (Autonomous)


scanf("%d",&g);
AP=((a-(((b/c)*d)+e))*(f+g));
printf("after evaluation result is :%d ",AP);
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
enter value of a :
12
enter value of b :
65
enter value of c :
96
enter value of d :
25
enter value of e :
30
enter value of f :
45
enter value of g :
25
after evaluation result is :-1260

Test Case - 2

Page No: 15
User Output
enter value of a :
11

ID: 23911A1268
enter value of b :
3
enter value of c :
112
enter value of d :
5
enter value of e :
6
enter value of f :
98

2023-2027-IT-B
enter value of g :
56
after evaluation result is :770

Vidya Jyothi Institute of Technology (Autonomous)


Exp. Name: Program to read two values and do the
S.No: 9 Date: 2023-11-12
arithmetic operations.

Aim:

Page No: 16
Write a C program to read two values and do the arithmetic operations ( +, - , * , / , % )
Source Code:

arithmetic.c

ID: 23911A1268
#include <stdio.h>
int main()
{
int a,b,Addition,Subtraction,Multiplication,Division,Modulus;
printf("Enter a value: ",a);
scanf("%d",&a);
printf("Enter b value: ",b);
scanf("%d",&b);
Addition = a + b;
printf("Addition: %d\n",Addition);
Subtraction = a - b;
printf("Subtraction: %d\n",Subtraction);

2023-2027-IT-B
Multiplication = a * b;
printf("Multiplication: %d\n",Multiplication);
Division = a / b;
printf("Division: %d\n",Division);
Modulus = a % b;
printf("Modulus: %d\n",Modulus);

Vidya Jyothi Institute of Technology (Autonomous)


return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter a value:
12
Enter b value:
3
Addition: 15
Subtraction: 9
Multiplication: 36
Division: 4
Modulus: 0

Test Case - 2

User Output
Enter a value:
4
18

Modulus: 2
Division: 4
Addition: 22
Enter b value:

Subtraction: 14
Multiplication: 72

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 17
Exp. Name: Program to demonstrate assignment
S.No: 10 Date: 2023-11-30
operators ( += , -= , *= , /= , %= , &= , ^= , |= )

Aim:

Page No: 18
Write a C program to demonstrate assignment operators ( += , -= , *= , /= , %= , &= , ^= , |= )
Source Code:

assignment.c

ID: 23911A1268
#include <stdio.h>
int main(){
int a,c;
printf("Enter a value: ");
scanf("%d",&a);
c=a;
printf("After assigning a value to c, c value is: %d\n",c);
c+=a;
printf("+= Value of c: %d\n",c);
c-=a;
printf("-= Value of c: %d\n",c);
c*=a;

2023-2027-IT-B
printf("*= Value of c: %d\n",c);
c/=a;
printf("/= Value of c: %d\n",c);
c%=a;
printf(">>= Value of c: %d\n",c);
c&=a;
printf("&= Value of c: %d\n",c);

Vidya Jyothi Institute of Technology (Autonomous)


c^=a;
printf("^= Value of c: %d\n",c);
c|=a;
printf("|= Value of c: %d\n",c);
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter a value:
18
After assigning a value to c, c value is: 18
+= Value of c: 36
-= Value of c: 18
*= Value of c: 324
/= Value of c: 18
>>= Value of c: 0
&= Value of c: 0
^= Value of c: 18
|= Value of c: 18
Test Case - 2

User Output
Enter a value:
314

Page No: 19
After assigning a value to c, c value is: 314
+= Value of c: 628
-= Value of c: 314
*= Value of c: 98596

ID: 23911A1268
/= Value of c: 314
>>= Value of c: 0
&= Value of c: 0
^= Value of c: 314
|= Value of c: 314

2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
Exp. Name: Program to demonstrate the use of
S.No: 11 Date: 2023-11-30
relational operators. ( <= , > , != )

Aim:

Page No: 20
Write a C program to demonstrate the use of relational operators. ( <= , > , != )
Source Code:

relational.c

ID: 23911A1268
#include <stdio.h>
int main(){
int a,b;
printf("Enter a value: ");
scanf("%d",&a);
printf("Enter b value: ");
scanf("%d",&b);
printf("A<=B: %d\n",a<=b);
printf("A>B: %d\n",a>b);
printf("A!=B: %d\n",a!=b);
return 0;
}

2023-2027-IT-B
Execution Results - All test cases have succeeded!
Test Case - 1

Vidya Jyothi Institute of Technology (Autonomous)


User Output
Enter a value:
12
Enter b value:
3
A<=B: 0
A>B: 1
A!=B: 1

Test Case - 2

User Output
Enter a value:
324
Enter b value:
116
A<=B: 0
A>B: 1
A!=B: 1
Exp. Name: Program to demonstrate the use of
S.No: 12 relational and all bitwise operators. ( & , | , ^ , ~ , Date: 2023-11-30
<< , >> )

Page No: 21
Aim:
Write a C program to demonstrate the use of relational and all bitwise operators. ( & , | , ^ , ~ , << , >> )
Source Code:

bitwise.c

ID: 23911A1268
#include <stdio.h>
int main(){
int a,b;
printf("Enter a value: ");
scanf("%d",&a);
printf("Enter b value: ");
scanf("%d",&b);
printf("Value of a&b is: %d\n",a&b);
printf("Value of a|b is: %d\n",a|b);
printf("Value of a^b is: %d\n",a^b);
printf("Value of ~a is: %d\n",~a);

2023-2027-IT-B
printf("Value of a<<b is: %d\n",a<<b);
printf("Value of a>>b is: %d\n",a>>b);
return 0;
}

Vidya Jyothi Institute of Technology (Autonomous)


Execution Results - All test cases have succeeded!
Test Case - 1

User Output
Enter a value:
60
Enter b value:
13
Value of a&b is: 12
Value of a|b is: 61
Value of a^b is: 49
Value of ~a is: -61
Value of a<

Value of a>>b is: 0

Test Case - 2

User Output
Enter a value:
329
Enter b value:
246
Value of a&b is: 64
Value of a|b is: 511
Value of a^b is: 447
Value of ~a is: -330

Page No: 22
Value of a<

Value of a>>b is: 0

ID: 23911A1268
2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
Exp. Name: Program on logical AND operator ( &&
S.No: 13 Date: 2023-11-30
)

Aim:

Page No: 23
Write a C program on logical AND operator ( && )
Source Code:

AND.c

ID: 23911A1268
#include <stdio.h>
int main() {
int a,b;
printf("0-FALSE 1-TRUE\n");
printf("Enter a value: ");
scanf("%d",&a);
printf("Enter b value: ");
scanf("%d",&b);
printf("AND operator result of a&&b: %d\n",a&&b);
return 0;
}

2023-2027-IT-B
Execution Results - All test cases have succeeded!
Test Case - 1

Vidya Jyothi Institute of Technology (Autonomous)


User Output
0-FALSE 1-TRUE
Enter a value:
1
Enter b value:
0
AND operator result of a&&b: 0

Test Case - 2

User Output
0-FALSE 1-TRUE
Enter a value:
0
Enter b value:
0
AND operator result of a&&b: 0
S.No: 14 Exp. Name: Program on logical OR operator ( || ) Date: 2023-11-30

Aim:
Write a C program on logical OR operator ( || )

Page No: 24
Source Code:

OR.c

#include <stdio.h>

ID: 23911A1268
int main() {
int a,b;
printf("0-FALSE 1-TRUE\n");
printf("Enter a value: ");
scanf("%d",&a);
printf("Enter b value: ");
scanf("%d",&b);
printf("OR operator result of a||b: %d\n",a||b);
return 0;
}

2023-2027-IT-B
Execution Results - All test cases have succeeded!
Test Case - 1

User Output

Vidya Jyothi Institute of Technology (Autonomous)


0-FALSE 1-TRUE
Enter a value:
1
Enter b value:
0
OR operator result of a||b: 1

Test Case - 2

User Output
0-FALSE 1-TRUE
Enter a value:
0
Enter b value:
0
OR operator result of a||b: 0
Exp. Name: Program Using Conditional Control
S.No: 15 Date: 2023-11-30
Statements(if,if-else,nested if).

Aim:

Page No: 25
Write a C program to print the Number entered by the user only if the number entered is Positive.

ALGORITHM:

Step 1: Start

ID: 23911A1268
Step 2: Input num
Step 3: Check if(num>0) then
Step 3.1: Print "number is positive"
else
Step 3.2: Print "number is negative"
Step 4: Stop
Source Code:

c.c

#include <stdio.h>
int main(){

2023-2027-IT-B
int a;
printf("Enter a number to check: ");
scanf("%d",&a);
if (a>0)
printf("Number is positive\n");
else{
printf("Number is negative\n");

Vidya Jyothi Institute of Technology (Autonomous)


}
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter a number to check:
3547
Number is positive

Test Case - 2

User Output
Enter a number to check:
-3147
Number is negative
Exp. Name: Program to find the biggest of 3
S.No: 16 Date: 2023-12-13
numbers.

Aim:

Page No: 26
Write a C program to find the Biggest of 3 numbers.

ALGORITHM:

Step 1: Start

ID: 23911A1268
Step 2: Input a,b,c
Step 3: Check if(a>b and a>c) then
Step 3.1: Print "a is greatest"
else
Step 4: Check if(b>a and b>c) then
Step 4.1: Print "b is greatest"
else
Step 5: Check if(c>a and c>b) then
Step 5.1: Print "c is greatest"
else
Step 6: Stop
Source Code:

2023-2027-IT-B
largest.c
#include <stdio.h>
int main() {
int a,b,c;
printf("Number 1: ");

Vidya Jyothi Institute of Technology (Autonomous)


scanf("%d",&a);
printf("Number 2: ");
scanf("%d",&b);
printf("Number 3: ");
scanf("%d",&c);
if(a>=b && a>=c)
{
printf("%d is greater among three\n",a);
}
else if(b>=a && b>=c)
{
printf("%d is greater among three\n",b);
}
else
{
printf("%d is greater among three\n",c);
}
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Number 1:
10
Number 2:
11
Number 3:

Page No: 27
12
12 is greater among three

Test Case - 2

ID: 23911A1268
User Output
Number 1:
58
Number 2:
96
Number 3:
42
96 is greater among three

2023-2027-IT-B
Test Case - 3

User Output
Number 1:
89

Vidya Jyothi Institute of Technology (Autonomous)


Number 2:
27
Number 3:
52
89 is greater among three
Exp. Name: Program to check whether a given
S.No: 17 Date: 2023-12-13
number is multiple of 5 or not.

Aim:

Page No: 28
Write a C program to check whether a given number is multiple of 5 or not.

ALGORITHM:

Step 1: Start

ID: 23911A1268
Step 2: Input num1
Step 3: Check if(num1 is divisible by 5) then
Step 3.1: Print "number is a multiple of 5"
else
Step 3.2: Print "number is not a multiple of 5"
Step 4: Stop
Source Code:

multiple.c
#include <stdio.h>
int main(){

2023-2027-IT-B
int n,i,sum=0;
printf("Enter a number to check: ");
scanf("%d",&n);
if(n % 5==0)
{
printf("%d is a multiple of 5\n",n);
}

Vidya Jyothi Institute of Technology (Autonomous)


else
{
printf("%d is not a multiple of 5\n",n);
}
return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter a number to check:
20
20 is a multiple of 5

Test Case - 2

User Output
Enter a number to check:
67
67 is not a multiple of 5
Exp. Name: Program to relate two integers entered
S.No: 18 Date: 2023-12-13
by user using = or > or < sign.

Aim:

Page No: 29
Write a C program to relate two integers entered by the user using = or > or < sign.

ALGORITHM:

Step 1: Start

ID: 23911A1268
Step 2: Input num1,num2;
Step 3: Check if(num1 ==num2) then
Step 3.1: Print "Both the numbers are Equal"
else
Step 4: Check if(num1<num2)then
Step 5: Print "num1 is greater than num2"
else
Step 6: Print "num1 is less than num2"
Step 7: Stop
Source Code:

operators.c

2023-2027-IT-B
#include<stdio.h>
int main(){
int n1,n2;
printf("Number 1: ");
scanf("%d",&n1);
printf("Number 2: ");

Vidya Jyothi Institute of Technology (Autonomous)


scanf("%d",&n2);
if(n1 ==n2)
{
printf("Result: %d = %d\n",n1,n2);
}
else if(n1<n2)
{
printf("Result: %d < %d\n",n1,n2);
}
else{
printf("Result: %d > %d\n",n1,n2);
}
return 0;

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Number 1:
20
Number 2:
20
Result: 20 = 20

Test Case - 2

Page No: 30
User Output
Number 1:
25
Number 2:

ID: 23911A1268
98
Result: 25 < 98

Test Case - 3

User Output
Number 1:
112
Number 2:
63

2023-2027-IT-B
Result: 112 > 63

Vidya Jyothi Institute of Technology (Autonomous)


Exp. Name: Program to print the student grade
S.No: 20 Date: 2023-12-21
based on average marks.

Aim:

Page No: 31
Write a C program to print the student grade based on average marks: If avg>=70 grade=Distinction , if
avg>=60 but <70grade="First class", If avg>45 but<60 grade="Second class" otherwise grade="FaiI".

Grades should be any one of the following


Distinction

ID: 23911A1268
First class
Second class
FaiI
Pass

2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
Source Code:

Marks.c
#include <stdio.h>
#include <math.h>
void main(){
int m1,m2,m3,m4,m5,avg;
printf("Enter the 5 subjects marks: ");

Page No: 32
scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);
avg=(m1 + m2 + m3 + m4 + m5)/5;
if(m1<35||m2<35||m3<35||m4<35||m5<35)
{
printf("Fail\n");

ID: 23911A1268
}
else if(avg >= 70)
{
printf("Distinction\n");
}
else if(avg >= 60 && avg<70)
{
printf("First class\n");
}
else if(avg > 45 && avg < 60)
{
printf("Second class\n");

2023-2027-IT-B
}
else
{
printf("Pass\n");
}
}

Vidya Jyothi Institute of Technology (Autonomous)


Execution Results - All test cases have succeeded!
Test Case - 1

User Output
Enter the 5 subjects marks:
92 87 89 78 91
Distinction

Test Case - 2

User Output
Enter the 5 subjects marks:
68 71 70 55 63
First class

Test Case - 3

User Output
Enter the 5 subjects marks:
95 45 34 74 54
Pass
Fail

User Output

36 36 36 36 38
Enter the 5 subjects marks:
Test Case - 4

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 33
Exp. Name: Program to check whether the given
S.No: 21 Date: 2023-12-15
year is leap year or not.

Aim:

Page No: 34
Write a C program to check whether the given year is a leap year or not.

ID: 23911A1268
Source Code:

LeapYear.c

2023-2027-IT-B
#include <stdio.h>
void main(){
int year;
printf("Enter the year: ");
scanf("%d",&year);
if(year % 400 == 0)

Vidya Jyothi Institute of Technology (Autonomous)


{
printf("%d is a leap year\n",year);
}
else if(year % 100 == 0)
{
printf("%d is not a leap year\n",year);
}
else if(year % 4 == 0)
{
printf("%d is a leap year\n",year);
}
else
{
printf("%d is not a leap year\n",year);
}
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter the year:
1600
1600 is a leap year
2300
User Output
Enter the year:

2300 is not a leap year


Test Case - 2

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 35
Exp. Name: Program to calculate value of f(x) if x
S.No: 22 Date: 2023-12-24
has different ranges of given values.

Aim:

Page No: 36
Write a C program to calculate the value of f(x) if x has different ranges of values as below.

f(x) = x2 + 2 if 0<=x<=10
f(x) = x2 + 2x if 11<=x<=20
f(x) = x3 + 2x2 if 21<=x<=30

ID: 23911A1268
f(x) = 0 if x > 30
Source Code:

range.c

#include <stdio.h>
#include<math.h>
int main(){
int x,f;
printf("Enter x Value:");
scanf("%d",&x);
if(x>=0&&x<=10)

2023-2027-IT-B
{
f=x*x+2;
printf("Value of F(x)= %d",f);
}
else if(x>=11 && x<=20){
f=x*x+2*x;
printf("Value of F(x)= %d",f);

Vidya Jyothi Institute of Technology (Autonomous)


}
else if(x>=21 && x<=30)
{
f=x*x*x+2*x*x;
printf("Value of F(x)= %d",f);
}
else {
printf("Value of F(x)= 0");
}

return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter x Value:
3
Value of F(x)= 11
Test Case - 2

User Output
Enter x Value:
11

Page No: 37
Value of F(x)= 143

Test Case - 3

ID: 23911A1268
User Output
Enter x Value:
25
Value of F(x)= 16875

Test Case - 4

User Output
Enter x Value:
33

2023-2027-IT-B
Value of F(x)= 0

Vidya Jyothi Institute of Technology (Autonomous)


Exp. Name: Program to check whether the given
input character is an integer or a character, if it is
S.No: 23 Date: 2023-12-23
a character then check whether it is an uppercase
or lowercase character.

Page No: 38
Aim:
Write a C program to check whether the given input character is an integer or a character, if it is
acharacter then check whether it is an uppercase or lowercase character.

ID: 23911A1268
ALGORITHM:
Step 1:Input a character (ch)
Step 2:check if (ch >=48 and ch <=57) then
Step 2.1:Print“Input character is a digit”
Step 3:check else if (ch >=65 and ch <=90) then
Step 3.1:Print “Input character is an uppercase character”
Step 4:check else if (ch >= 97 and ch <=122)then
Step 4.1:Print “Input character is a lowercase character”
Step 5:check else
Step 5.1:Print “Input character is a special character”
Step 6:Stop.
Source Code:

2023-2027-IT-B
Char.c
#include<stdio.h>
void main(){
char ch;

Vidya Jyothi Institute of Technology (Autonomous)


int n;
printf("Enter a character: ");
scanf("%s",&ch);
n=(int)(ch);
if(n >= 48 && n <= 57)
{
printf("Input character is digit\n");
}
else if(n>= 65 &&n <= 90)
{
printf("Input character is an uppercase character\n");
}
else if(n >=97 && n <= 122)
{
printf("Input character is a lowercase character\n");
}
else{
printf("Input character is a special character\n");
}
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter a character:
9
Input character is digit

Test Case - 2

Page No: 39
User Output
Enter a character:
&

ID: 23911A1268
Input character is a special character

Test Case - 3

User Output
Enter a character:
b
Input character is a lowercase character

2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
Exp. Name: Program to check whether the given
S.No: 24 Date: 2023-12-18
number is positive or not.

Aim:

Page No: 40
Write a C program to check whether the given number is positive or not.
Source Code:

positive.c

ID: 23911A1268
#include<stdio.h>
int main(){
float n;
printf("Enter a number: ");
scanf("%f",&n);
if(n>0)
printf("You entered a positive number\n");
else if(n<0)
printf("You entered a negative number\n");
else if(n == 0.0)
printf("You entered 0\n");
return 0;

2023-2027-IT-B
}

Execution Results - All test cases have succeeded!

Vidya Jyothi Institute of Technology (Autonomous)


Test Case - 1

User Output
Enter a number:
15.8
You entered a positive number

Test Case - 2

User Output
Enter a number:
-96.214
You entered a negative number

Test Case - 3

User Output
Enter a number:
0.0
You entered 0
Exp. Name: Program to check given triangle is valid
S.No: 25 Date: 2023-12-22
or not.

Aim:

Page No: 41
Write a C program to check whether the given triangle is valid or not.

Note: The given triangle is valid if the sum of the anglesis equalto 180 .

Source Code:

ID: 23911A1268
triangle.c
#include <stdio.h>
void main(){
int s1,s2,s3,sum;
printf("Enter three angles of triangle: ");
scanf("%d%d%d", &s1, &s2, &s3);
(sum = s1 + s2 + s3);
if (sum == 180 && s1 > 0 && s2 > 0 && s3 >0)
{
printf("Triangle is valid\n");
}

2023-2027-IT-B
else
{
printf("Triangle is not valid\n");
}
}

Vidya Jyothi Institute of Technology (Autonomous)


Execution Results - All test cases have succeeded!
Test Case - 1

User Output
Enter three angles of triangle:
60 60 60
Triangle is valid

Test Case - 2

User Output
Enter three angles of triangle:
120 60 0
Triangle is not valid
Exp. Name: Program to check the eligibility for
S.No: 26 Date: 2023-12-18
voting.

Aim:

Page No: 42
Write a C program to check the eligibility for voting.
Source Code:

voting.c

ID: 23911A1268
#include <stdio.h>
int main() {
int n;
printf("Enter the age of the person: ");
scanf("%d",&n);
if (n>=18)
{
printf("Eligible for voting\n");
}
else
{
printf("Not eligible for voting\n");

2023-2027-IT-B
}
return 0;
}

Execution Results - All test cases have succeeded!

Vidya Jyothi Institute of Technology (Autonomous)


Test Case - 1

User Output
Enter the age of the person:
22
Eligible for voting

Test Case - 2

User Output
Enter the age of the person:
6
Not eligible for voting
S.No: 27 Exp. Name: Basic banking system using goto Date: 2023-12-28

Aim:
write a C program that simulates a basic banking system? The program should display a menu for users to

Page No: 43
check their balance, deposit money, withdraw funds, or exit the system. Use the goto statement to
facilitate user interactions, and ensure that deposit and withdrawal operations are valid and the process
should be carried until the user selects exit option.
Source Code:

ID: 23911A1268
banking.c

2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
#include <stdio.h>

int main() {
double balance;
int choice;

Page No: 44
double amount;

printf("Enter the amount:");


scanf("%lf", &balance);
//write the missing part in simple banking system block

ID: 23911A1268
menu:

printf("Simple Banking System\n");


printf("Menu:\n");
printf("1.Check Balance\n");
printf("2.Deposit Money\n");
printf("3.Withdraw Money\n");
printf("4.Exit\n");
printf("Enter your choice:");
scanf("%d",&choice );

2023-2027-IT-B
switch (choice) {
case 1:
printf("balance:%.2f\n",balance);
goto menu;
break;
case 2:
printf("amount:");

Vidya Jyothi Institute of Technology (Autonomous)


scanf("%lf",&amount);
if ( amount > 0) {
balance += amount;
//write the missing operation for Deposit

printf("new balance:%.2f\n", balance );


} else {
printf("Invalid amount\n");
}
goto menu;
break;
case 3:
printf("amount:");
scanf("%lf",&amount);
if ( amount> 0 && amount <= balance ) {
balance -= amount;
//write the missing operation for withdrawl

printf("Withdrawal successful! Your new balance is:%.2f\n", balance);


} else {
printf("Invalid amount or insufficient balance\n");
}
goto menu;
break;
break;
default:
printf("Invalid choice\n");
// write the missing code
goto menu;

Page No: 45
}

return 0;
}

ID: 23911A1268
Execution Results - All test cases have succeeded!
Test Case - 1

User Output
Enter the amount:
10000
Simple Banking System
Menu:

2023-2027-IT-B
1.Check Balance
2.Deposit Money
3.Withdraw Money
4.Exit
Enter your choice:
1

Vidya Jyothi Institute of Technology (Autonomous)


balance:10000.00
Simple Banking System
Menu:
1.Check Balance
2.Deposit Money
3.Withdraw Money
4.Exit
Enter your choice:
2
amount:
10000
new balance:20000.00
Simple Banking System
Menu:
1.Check Balance
2.Deposit Money
3.Withdraw Money
4.Exit
Enter your choice:
4
Exiting
Test Case - 2

User Output
Enter the amount:
40000

Page No: 46
Simple Banking System
Menu:
1.Check Balance
2.Deposit Money

ID: 23911A1268
3.Withdraw Money
4.Exit
Enter your choice:
5
Invalid choice
Simple Banking System
Menu:
1.Check Balance
2.Deposit Money
3.Withdraw Money
4.Exit

2023-2027-IT-B
Enter your choice:
1
balance:40000.00
Simple Banking System
Menu:

Vidya Jyothi Institute of Technology (Autonomous)


1.Check Balance
2.Deposit Money
3.Withdraw Money
4.Exit
Enter your choice:
4
Exiting
Exp. Name: Problem solving with Selection
S.No: 28 Date: 2023-12-21
Statements

Aim:

Page No: 47
Write a program to read two integer values and if one of the number is 100 or the sum of the numbers is
100, print true , otherwise print false .

At the time of execution, the program should print the message on the console as:

ID: 23911A1268
Enter two integer values :

For example, if the user gives the input as 100 -10 :

Enter two integer values : 100 -10

then the program should print the result as:

true

Note: Do use the printf() function with a newline character ( \n ).


Source Code:

2023-2027-IT-B
IfelseIfExample4.c

#include <stdio.h>
void main(){
int n1,n2,n;

Vidya Jyothi Institute of Technology (Autonomous)


printf("Enter two integer values : ");
scanf("%d%d",&n1,&n2);
if(n1 == 100 || n2 == 100 || n1+n2==100)
{
printf("true\n");
}
else
{
printf("false\n");
}
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter two integer values :
100 -10
true

Test Case - 2

User Output
false
-10 -90
Enter two integer values :

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 48
Exp. Name: Problem solving with Selection
S.No: 29 Date: 2023-12-30
Statements

Aim:

Page No: 49
Write a program to read two integer values for the variables first_number, second_number and calculate
the difference between first_number and the second_number (first_number - second_number).

If the value of the difference is between -25 and 25 (both not included) then double the value and

ID: 23911A1268
print it, else print the difference as it is.

For example, if 100 and 50 are given, the program should print 50 (since 100-50 = 50, which is not
between -25 and 25).
If 15 and 7 are given, the program should print 16 (since the difference of 15 and 7 is 8 which is
between -25 and 25)

At the time of execution, the program should print the message on the console as:

Enter 2 integer values :

For example, if the user gives the input as 100 90 :

2023-2027-IT-B
Enter 2 integer values : 100 90

then the program should print the result as:

20

Vidya Jyothi Institute of Technology (Autonomous)


Note: Do use the printf() function with a newline character ( \n ).
Source Code:

IfelseIfExample2.c
#include<stdio.h>
void main(){
int a,b;
printf("Enter 2 integer values : ");
scanf("%d%d",&a,&b);
int c = a-b;
if(c == 10)
{
printf("%d\n",c*2);
}
else{
printf("%d\n",c);
}
}

Execution Results - All test cases have succeeded!


Test Case - 1
User Output
Enter 2 integer values :
100 50
50

Page No: 50
Test Case - 2

User Output

ID: 23911A1268
Enter 2 integer values :
100 90
20

2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
Exp. Name: Problem solving with Selection
S.No: 30 Date: 2023-12-31
Statements

Aim:

Page No: 51
Write a program to read age of four members and print how many members have age greater than 60 .

Example: if the values given are 20, 40, 65 and 80, the program should print 2.

ID: 23911A1268
At the time of execution, the program should print the message on the console as:

Enter four members age :

For example, if the user gives the input as 20 40 65 80 :

Enter four members age : 20 40 65 80

then the program should print the result as:

Note: Do use the printf() function with a newline character ( \n ) at the end.

2023-2027-IT-B
Source Code:

IfelseIfExample9.c
#include<stdio.h>
void main(){

Vidya Jyothi Institute of Technology (Autonomous)


int a,b,c,d,age,count;
printf("Enter four members age : ");
scanf("%d%d%d%d",&a,&b,&c,&d);
for(int i=1;i<2;i++)
{
if(a>=60)
{
count++;
}
if(b>=60)
{
count++;
}
if(c>=60)
{
count++;
}
if(d>=60)
{
count++;
}
}
printf("%d\n",count);
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter four members age :
61 37 59 72

Page No: 52
2

Test Case - 2

ID: 23911A1268
User Output
Enter four members age :
12 45 36 57
0

2023-2027-IT-B
Vidya Jyothi Institute of Technology (Autonomous)
Exp. Name: Problem solving with Selection
S.No: 34 Date: 2023-12-30
Statements

Aim:

Page No: 53
Write a program to read an integer value for the variable hour and if the hour is between 9 and 17
(both inclusive), print Working hour , otherwise print Non-working hour .

At the time of execution, the program should print the message on the console as:

ID: 23911A1268
Enter hour :

For example, if the user gives the input as 18 :

Enter hour : 18

then the program should print the result as:

Non-working hour

Note: Do use the printf() function with a newline character ( \n ).


Source Code:

2023-2027-IT-B
IfelseIfExample3.c
#include<stdio.h>
void main(){
int hour ;

Vidya Jyothi Institute of Technology (Autonomous)


printf("Enter hour : ");
scanf("%d",&hour);
if(hour>=9 && hour<=17)
{
printf("Working hour\n");
}
else{
printf("Non-working hour\n");
}
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter hour :
9
Working hour

Test Case - 2

User Output
Enter hour :
18
Non-working hour

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 54
Exp. Name: Print months in a year using switch
S.No: 36 Date: 2023-12-30
case statement

Aim:

Page No: 55
Write a C program to display month name according to the month number using switch case statement.

Note: If the given input number is not in the range i.e., other than 1 to 12, the output should be as "Invalid
month number"
Source Code:

ID: 23911A1268
DisplayMonth.c
#include<stdio.h>
void main(){
int choice;
printf("Enter month number : ");
scanf("%d",&choice);
switch(choice)
{
case 1 : printf("January\n");
break;

2023-2027-IT-B
case 2 : printf("February\n");
break ;
case 3 : printf("March\n");
break;
case 4 : printf("April\n");
break;
case 5 : printf("May\n");

Vidya Jyothi Institute of Technology (Autonomous)


break;
case 6 : printf("June\n");
break;
case 7 : printf("July\n");
break;
case 8 : printf("August\n");
break;
case 9 : printf("September\n");
break;
case 10 : printf("October\n");
break;
case 11 : printf("November\n");
break;
case 12 : printf("December\n");
break;
default : printf("Invalid month number\n");
}
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter month number :
1
January

Test Case - 2

Page No: 56
User Output
Enter month number :
11
November

ID: 23911A1268
Test Case - 3

User Output
Enter month number :
13
Invalid month number

Test Case - 4

2023-2027-IT-B
User Output
Enter month number :
9
September

Vidya Jyothi Institute of Technology (Autonomous)


Test Case - 5

User Output
Enter month number :
4
April

Test Case - 6

User Output
Enter month number :
2
February

Test Case - 7

User Output
Enter month number :
8
August
Test Case - 8

User Output
Enter month number :
6

Page No: 57
June

Test Case - 9

ID: 23911A1268
User Output
Enter month number :
12
December

Test Case - 10

User Output
Enter month number :
0

2023-2027-IT-B
Invalid month number

Test Case - 11

User Output

Vidya Jyothi Institute of Technology (Autonomous)


Enter month number :
7
July
S.No: 37 Exp. Name: Understanding if-else-if statement Date: 2023-12-30

Aim:
See the below code which uses a if-else-if statement for calculating AM or PM for a given hour.

Page No: 58
In the main() function read an integer value between 0 and 23 for the variable hour and use if-else-if
statement to display AM or PM.

ID: 23911A1268
Fill in the if condition to check if the given hour is between 0 and 11 (both inclusive) for AM. Fill in the
else if condition to check if the given hour is between 12 and 23 (both inclusive) for PM.

Note: Do use the printf() function with a newline character ( \n ).


Source Code:

IfelseIfDemo4.c
#include <stdio.h>
void main(){
int hour;
printf("Enter hour : ");

2023-2027-IT-B
scanf("%d", &hour);
if (hour > 0 && hour <= 11 ) { //fill the condition for AM here
printf("AM\n");
} else if (hour > 12 && hour <= 23 ) { //fill the condition for PM here
printf("PM\n");
} else {
printf("Invalid Hour!!\n");

Vidya Jyothi Institute of Technology (Autonomous)


}
}

Execution Results - All test cases have succeeded!


Test Case - 1

User Output
Enter hour :
9
AM

Test Case - 2

User Output
Enter hour :
22
PM
24
User Output
Enter hour :

Invalid Hour!!
Test Case - 3

Vidya Jyothi Institute of Technology (Autonomous) 2023-2027-IT-B ID: 23911A1268 Page No: 59

You might also like