0% found this document useful (0 votes)
12 views151 pages

Lab Record Download

The document contains a series of C programming exercises aimed at teaching basic programming concepts, including displaying messages, scanning variables, performing arithmetic operations, calculating sums and averages, temperature conversions, simple interest calculations, and finding square roots. Each exercise includes the aim, input/output formats, source code, and execution results demonstrating successful test cases. The exercises are structured to provide hands-on experience with fundamental programming tasks.

Uploaded by

blanushka004
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)
12 views151 pages

Lab Record Download

The document contains a series of C programming exercises aimed at teaching basic programming concepts, including displaying messages, scanning variables, performing arithmetic operations, calculating sums and averages, temperature conversions, simple interest calculations, and finding square roots. Each exercise includes the aim, input/output formats, source code, and execution results demonstrating successful test cases. The exercises are structured to provide hands-on experience with fundamental programming tasks.

Uploaded by

blanushka004
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/ 151

Date: 2024-09-

1 :oN egaP
S.No: 1 Exp. Name: Display hello world message
19

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to display hello world message
Source Code:

hello.c

#include<stdio.h>
void main()
{
printf("Hello World\n");
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Hello World

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Scan all data type variables Date: 2024-09-
S.No: 2

2 :oN egaP
and display them 19

Aim:
Write a C program to scan all data type variables(int, float, char, double) as input and print

2 Q 4 5 A 1 9 B 4 2 : DI
them as output.

Input Format:
• First Line: An integer, entered after the prompt "integer: ".
• Second Line: A floating-point number, entered after the prompt "floating-point
number: ".
• Third Line: A character, entered after the prompt "character: ".
• Fourth Line: A double-precision floating-point number, entered after the prompt
"double: ".

Output Format:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
• First Line: A message "You entered:".
• Second Line: The integer entered, in the format "Integer: [integerVar]".
• Third Line: The floating-point number entered, formatted to six decimal places, in
the format "Float: [floatVar]".
• Fourth Line: The character entered, in the format "Character: [charVar]".
• Fifth Line: The double-precision floating-point number entered, formatted to six
decimal places, in the format "Double: [doubleVariable]".

)suomonotuA( egelloC gnireenignE RKRS


Note: Please add Space before %c which removes any white space (blanks, tabs, or
newlines).
Source Code:

scan.c
#include<stdio.h>

3 :oN egaP
int main()
{
int a;
float f;
char c;

2 Q 4 5 A 1 9 B 4 2 : DI
double d;
printf("integer: ");
scanf("%d",&a);
printf("floating-point number: ");
scanf("%f",&f);
printf("character: ");
scanf(" %c",&c);
printf("double: ");
scanf("%lf",&d);
printf("You entered:\n");
printf("Integer: %d\n",a);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Float: %f\n",f);
printf("Character: %c\n",c);
printf("Double: %lf\n",d);
return 0;
}

Execution Results - All test cases have succeeded!

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 1

User Output

integer:
9
floating-point number:
12.0254
character:
C
double:
12.02543124
You entered:
Integer: 9
Float: 12.025400
Character: C
Double: 12.025431
Test Case - 2

4 :oN egaP
User Output

integer:
-10

2 Q 4 5 A 1 9 B 4 2 : DI
floating-point number:
12.2546
character:
T
double:
12.6789678
You entered:
Integer: -10
Float: 12.254600
Character: T

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Double: 12.678968

)suomonotuA( egelloC gnireenignE RKRS


Date: 2024-09-
S.No: 3 Exp. Name: Arithmetic operations

5 :oN egaP
20

Aim:
Write a C program to perform arithmetic operations like +,-,*,/,% on two input variables.

2 Q 4 5 A 1 9 B 4 2 : DI
Input Format:
• The first line of input is an integer representing the value for first number
• The second line of input is an integer representing the value of second number

Output Format:
• The program prints the results of addition, subtraction, multiplication, division, and
modulus each on a new line.

Note : For Division and Modulo operation, the value of num2 must be greater than 0

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Add new line char \n at the end of output.
Source Code:

arithmeticOperations.c

#include<stdio.h>
int main()
{
int num1,num2,Sum,Difference,Product,Division,Modulus;

)suomonotuA( egelloC gnireenignE RKRS


printf("num1: ");
scanf("%d",&num1);
printf("num2: ");
scanf("%d",&num2);
Sum=num1+num2;
printf("Sum: %d\n",Sum);
Difference=num1-num2;
printf("Difference: %d\n",Difference);
Product=num1*num2;
printf("Product: %d\n",Product);
Division=num1/num2;
printf("Division: %d\n",Division);
Modulus=num1%num2;
printf("Modulus: %d\n",Modulus);
}

Execution Results - All test cases have succeeded!


6 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 1

Test Case - 2
User Output

User Output

1000

1002

2000
998

500
17

72
9
8

2
1

1
1

0
Exp. Name: Write a C program to find Date: 2024-09-
S.No: 4

7 :oN egaP
Sum and Average of three numbers 20

Aim:
Write a program to find the sum and average of the three given integers.

2 Q 4 5 A 1 9 B 4 2 : DI
Note: Use the printf() function with a newline character ( \n ) at the end.
Source Code:

Program314.c

#include<stdio.h>
int main()
{
int a,b,c,Sum;
float Average;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Enter three integers : ");
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
Sum=a+b+c;
printf("Sum of %d, %d and %d : %d\n",a,b,c,Sum);
Average=(a+b+c)/3.0;
printf("Average of %d, %d and %d : %f\n",a,b,c,Average);

)suomonotuA( egelloC gnireenignE RKRS


}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter three integers :


121 34 56
Sum of 121, 34 and 56 : 211
Average of 121, 34 and 56 : 70.333336

Test Case - 2

User Output

Enter three integers :


Sum of 5, 8 and 3 : 16
Average of 5, 8 and 3 : 5.333333

8 :oN egaP
Test Case - 3

2 Q 4 5 A 1 9 B 4 2 : DI
User Output

Enter three integers :


-1 5 -6
Sum of -1, 5 and -6 : -2
Average of -1, 5 and -6 : -0.666667

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Temperature conversions
Date: 2024-09-

9 :oN egaP
S.No: 5 from Centigrade to Fahrenheit and vice
22
versa.

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to perform temperature conversions from Centigrade to Fahrenheit

Note : Refer to sample test cases for input and output format
Source Code:

temperature.c

#include<stdio.h>
int main()
{
float c,f;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
scanf("%f",&c);
f=(c*1.8)+32 ;
printf("%.2f Celsius = %.2f Fahrenheit\n",c,f);
}

Execution Results - All test cases have succeeded!

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 1

User Output

37.5
37.50 Celsius = 99.50 Fahrenheit

Test Case - 2

User Output

-20
-20.00 Celsius = -4.00 Fahrenheit
Date: 2024-09-
S.No: 6 Exp. Name: Problem Solving

01 :oN egaP
20

Aim:
Write a program to calculate the simple interest by reading principle amount, rate of

2 Q 4 5 A 1 9 B 4 2 : DI
interest and time.

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

Enter principle amount, rate of interest, time of loan :

For example, if the user gives the input as:

Enter principle amount, rate of interest, time of loan :


23456.78 3.5 2.5

D- B S C & DI A- 8 2 0 2- 4 2 0 2
then the program should print the result as:

Simple Interest = 2052.468018

Note: Do use the printf() function and ensure that there is a '\n' at the end after print
the result.
Source Code:

)suomonotuA( egelloC gnireenignE RKRS


Program3.c

//simple c program about simple Interest


#include<stdio.h>
int main()
{
int p,t,r;
float SimpleInterest;
printf("Enter principle amount, rate of interest, time of
loan : ");
scanf("%d",&p);
scanf("%d",&r);
scanf("%d",&t);
SimpleInterest=(p *r *t) /100;
printf("Simple Interest = %6f\n",SimpleInterest);
}

Execution Results - All test cases have succeeded!


Test Case - 1

11 :oN egaP
User Output

Enter principle amount, rate of interest, time of loan :


2500 5 2
Simple Interest = 250.000000

2 Q 4 5 A 1 9 B 4 2 : DI
D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Calculate the square root of Date: 2024-09-
S.No: 7

21 :oN egaP
an integer 20

Aim:
Write a program that prompts the user to enter an integer and calculates its square root.

2 Q 4 5 A 1 9 B 4 2 : DI
Note:Print the result up to 3 decimal places.

Input format:
The program takes an integer as input with the print statement "Enter an integer: "
followed by the integer.

Output format:
The output is the floating point value formatted to three decimals that represents the
square root value of the user-given integer.

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Hint: You can use math library to perform mathematical operations.

Instruction: During writing your code, please follow the input and output layout as
mentioned in the sample test case.
Source Code:

squareRoot.c

//simple c progrm about square root of two integers

)suomonotuA( egelloC gnireenignE RKRS


#include<stdio.h>
#include<math.h>
int main()
{
int a;
float Squareroot;
printf("Enter an integer: ");
scanf("%d",&a);
Squareroot= sqrt(a);
printf("Square root: %.3f\n",Squareroot);
}

Execution Results - All test cases have succeeded!

Test Case - 1
31 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 2
Square root: 1.414

Square root: 2.000


Enter an integer:

Enter an integer:
User Output
2

4
Exp. Name: Calculate simple interest and Date: 2024-09-
S.No: 8

41 :oN egaP
compound interest 20

Aim:
Write a C program to calculate the simple interest and compound interest by reading

2 Q 4 5 A 1 9 B 4 2 : DI
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.

Input Format:
• Prompt the user to enter the values of P , R , T separated by space

Output Format:
• The First line of output represents the value of Simple Interest (SI)
• The Second line of output represents the value of Compount Interest (CI)

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Example:
Input:
5000 7 5
Output:
SI= 1750.000000
CI= 2012.760376

)suomonotuA( egelloC gnireenignE RKRS


(pr i nci pal ∗ r ate∗ ti me)
The formula to find simple interest is SI =
100
The formula to find compound interest is CI =

pr i nci pal ∗ pow(1 + ( r ate


), ti me) − pr i nci pal
100
Note: Use float data type for all the involved variables.
Source Code:

Program315.c
//simple c program about SI and CI

51 :oN egaP
#include<stdio.h>
#include<math.h>
int main()
{
float p,r,t,si,ci;

2 Q 4 5 A 1 9 B 4 2 : DI
printf("Enter P,R,T: ");
scanf("%f",&p);
scanf("%f",&r);
scanf("%f",&t);
si=(p*t*r)/100;
printf("SI= %f\n",si);
ci=p*(pow(1+(r/100),t))-p;
printf("CI= %f\n",ci);
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

5000 7 5
SI= 1750.000000

)suomonotuA( egelloC gnireenignE RKRS


CI= 2012.760376

Test Case - 2

User Output

10000 4.5 3.5


SI= 1575.000000
CI= 1665.596558
Exp. Name: Area of a triangle using Date: 2024-09-
S.No: 9

61 :oN egaP
heron's formula 20

Aim:
Write a program to find the area of a triangle using Heron's formula.

2 Q 4 5 A 1 9 B 4 2 : DI
During execution, the program should print the following message on the console:

sides:

For example, if the user gives the following as input (input is positive floating decimal
point numbers):

sides: 2.3 2.4 2.5

Then the program should print the result round off upto 2 decimal places as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
area: 2.49

Instruction: Your input and output layout must match with the sample test cases (values
as well as text strings).

The area of a triangle is given by Area = √ p(p − a)(p − b)(p − c) , where p is


half of the perimeter, or (a + b + c) / 2 . Let a,b,c be the lengths of the sides of the

)suomonotuA( egelloC gnireenignE RKRS


given triangle.

Hint: Use sqrt function defined in math.h header file


Source Code:

Program313.c
//to find the area of the triangle//

71 :oN egaP
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,p,area;

2 Q 4 5 A 1 9 B 4 2 : DI
printf("sides: ");
scanf("%f",&a);
scanf("%f",&b);
scanf("%f",&c);
p=(a+b+c)/2;
area=sqrt(p*(p-a)*(p-b)*(p-c));
printf("area: %.2f",area);
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

sides:
2.3 2.4 2.5
area: 2.49

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 2

User Output

sides:
2.6 2.7 2.8
area: 3.15
Exp. Name: Distance travelled by an Date: 2024-09-
S.No: 10

81 :oN egaP
object 20

Aim:
Write a program to find the distance travelled by an object.

2 Q 4 5 A 1 9 B 4 2 : DI
Sample Input and Output:

Enter the acceleration value : 2.5


Enter the initial velocity : 5.7
Enter the time taken : 20
Distance travelled : 614.000000

Note - 1: Use the formula to find distance, distance = ut + (1/2) at2 .

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Note: Use the printf() function with a newline character ( \n ) at the end.

Source Code:

DistanceTravelled.c

//to find the distance travelled by an object//


#include<stdio.h>
int main()

)suomonotuA( egelloC gnireenignE RKRS


{
float a,t,u,d;
printf("Enter the acceleration value : ");
scanf("%f",&a);
printf("Enter the initial velocity : ");
scanf("%f",&u);
printf("Enter the time taken : ");
scanf("%f",&t);
d=u*t+(a*t*t)/2;
printf("Distance travelled : %.6f\n",d);
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter the acceleration value :


4
Enter the initial velocity :

91 :oN egaP
5
Enter the time taken :
6
Distance travelled : 102.000000

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 2

User Output

Enter the acceleration value :


5
Enter the initial velocity :
0
Enter the time taken :

D- B S C & DI A- 8 2 0 2- 4 2 0 2
10
Distance travelled : 250.000000

Test Case - 3

User Output

Enter the acceleration value :

)suomonotuA( egelloC gnireenignE RKRS


2.5
Enter the initial velocity :
5.7
Enter the time taken :
20
Distance travelled : 614.000000

Test Case - 4

User Output

Enter the acceleration value :


50
Enter the initial velocity :
34.67
Enter the time taken :
6
Distance travelled : 1108.020020
Test Case - 5

02 :oN egaP
User Output

Enter the acceleration value :


125.6
Enter the initial velocity :

2 Q 4 5 A 1 9 B 4 2 : DI
45.8
Enter the time taken :
4
Distance travelled : 1188.000000

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Date: 2024-09-
S.No: 11 Exp. Name: Evaluate the expressions

12 :oN egaP
20

Aim:
Write a C program to evaluate the following expressions.

2 Q 4 5 A 1 9 B 4 2 : DI
a. A+B*C+(D*E) + F*G
b. A/B*C-B+A*D/3
c. A+++B---A
d. J= (i++) + (++i)

Note: consider expression as A++ + ++B - --A


Source Code:

evaluate.c

#include<stdio.h>

D- B S C & DI A- 8 2 0 2- 4 2 0 2
int main()
{
int a,b,c,d,e,f,g,i,j,k,l,m;
printf("Enter values for A, B, C, D, E, F, G, i: ");
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
scanf("%d",&d);
scanf("%d",&e);

)suomonotuA( egelloC gnireenignE RKRS


scanf("%d",&f);
scanf("%d",&g);
scanf("%d",&i);
k=a+b*c+(d*e) + f*g;
printf("a.A+B*C+(D*E) + F*G = %d\n",k);
l=a/b*c-b+a*d/3;
printf("b.A/B*C-B+A*D/3 = %d\n",l);
m=a++ + ++b- --a;
printf("c.A+++B---A = %d\n",m);
j=(i++) + (++i);
printf("d.J = (i++) + (++i) = %d\n",j);
}

Execution Results - All test cases have succeeded!

Test Case - 1
Enter values for A, B, C, D, E, F, G, i:
12345678

22 :oN egaP
a.A+B*C+(D*E) + F*G = 69
b.A/B*C-B+A*D/3 = -1
c.A+++B---A = 3
d.J = (i++) + (++i) = 18

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 2

User Output

Enter values for A, B, C, D, E, F, G, i:


10 20 60 30 40 4 6 1
a.A+B*C+(D*E) + F*G = 2434
b.A/B*C-B+A*D/3 = 80
c.A+++B---A = 21

D- B S C & DI A- 8 2 0 2- 4 2 0 2
d.J = (i++) + (++i) = 4

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Greatest of three numbers Date: 2024-09-
S.No: 12

32 :oN egaP
using a conditional operator 20

Aim:
Write a C program to display the greatest of three numbers using a conditional operator

2 Q 4 5 A 1 9 B 4 2 : DI
(ternary operator).

Input Format
The program prompts the user to enter three integers.

Output Format
The program prints the greatest of the three integers.

Source Code:

greatest.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
#include <stdio.h>

int main() {
int num1, num2, num3, greatest;

// Take input from user


printf("num1: ");
scanf("%d",&num1);

)suomonotuA( egelloC gnireenignE RKRS


printf("num2: ");
scanf("%d",&num2);

printf("num3: ");
scanf("%d",&num3);

// Find the greatest number using the conditional operator


greatest = num1>num2?num1:num2>num3?num2:num3;

// Display the greatest number


printf("Greatest number: %d\n",greatest);

return 0;
}
Execution Results - All test cases have succeeded!

42 :oN egaP
Test Case - 1

User Output

num1:

2 Q 4 5 A 1 9 B 4 2 : DI
8
num2:
9
num3:
90
Greatest number: 90

Test Case - 2

D- B S C & DI A- 8 2 0 2- 4 2 0 2
User Output

num1:
5
num2:
45
num3:
6

)suomonotuA( egelloC gnireenignE RKRS


Greatest number: 45
Exp. Name: Write a C program to Total Date: 2024-09-
S.No: 13

52 :oN egaP
and Average of 5 subjects marks 20

Aim:
Write a program to take marks of 5 subjects in integers, and find the total , average

2 Q 4 5 A 1 9 B 4 2 : DI
in float.

Sample Input and Output:

Enter 5 subjects marks : 55 56 57 54 55


Total marks : 277.000000
Average marks : 55.400002

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

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Source Code:

TotalAndAvg.c

#include<stdio.h>
int main()
{
int a,b,c,d,e;

)suomonotuA( egelloC gnireenignE RKRS


float g,f;
printf("Enter 5 subjects marks : ");
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
f=a+b+c+d+e;
printf("Total marks : %.6f\n",f);
g=f/5;
printf("Average marks : %.6f\n",g);
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter 5 subjects marks :


45 67 89 57 49
Total marks : 307.000000
Test Case - 2

62 :oN egaP
User Output

Enter 5 subjects marks :


55 56 57 54 55
Total marks : 277.000000

2 Q 4 5 A 1 9 B 4 2 : DI
Average marks : 55.400002

Test Case - 3

User Output

Enter 5 subjects marks :


90 97 95 92 91
Total marks : 465.000000
Average marks : 93.000000

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Test Case - 4

User Output

Enter 5 subjects marks :


20 30 66 77 44
Total marks : 237.000000

)suomonotuA( egelloC gnireenignE RKRS


Average marks : 47.400002

Test Case - 5

User Output

Enter 5 subjects marks :


56 78 88 79 64
Total marks : 365.000000
Average marks : 73.000000

Test Case - 6

User Output

Enter 5 subjects marks :


44 35 67 49 51
Total marks : 246.000000
Exp. Name: Write a Program to find the Date: 2024-09-
S.No: 14

72 :oN egaP
Max and Min of Four numbers 24

Aim:
Write a program to find the max and min of four numbers.

2 Q 4 5 A 1 9 B 4 2 : DI
Sample Input and Output :

Enter 4 numbers : 9 8 5 2
Max value : 9
Min value : 2

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

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Source Code:

MinandMaxOf4.c

)suomonotuA( egelloC gnireenignE RKRS


#include<stdio.h>

82 :oN egaP
int main()
{
int a,b,c,d;
printf("Enter 4 numbers : ");
scanf("%d %d %d %d",&a ,&b ,&c ,&d);

2 Q 4 5 A 1 9 B 4 2 : DI
if ((a>b)&&(a>c)&&(a>d))
{
printf("Max value : %d\n",a);
}
if((b>a)&&(b>c)&&(b>d))
{
printf("Max value : %d\n",b);
}
if((c>a)&&(c>b)&&(c>d))
{
printf("Max value : %d\n",c);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
}
if((d>a)&&(d>b)&&(d>c))
{
printf("Max value : %d\n",d);
}
if((a<b)&&(a<c)&&(a<d))
{
printf("Min value : %d\n",a);
}

)suomonotuA( egelloC gnireenignE RKRS


if((b<a)&&(b<c)&&(b<d))
{
printf("Min value : %d\n",b);
}
if((c<a)&&(c<b)&&(c<d))
{
printf("Min value : %d\n",c);
}
if((d<a)&&(d<b)&&(d<c))
{
printf("Min value : %d\n",d);
}
}

Execution Results - All test cases have succeeded!

Test Case - 1
User Output

92 :oN egaP
Enter 4 numbers :
9852
Max value : 9
Min value : 2

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 2

User Output

Enter 4 numbers :
112 245 167 321
Max value : 321
Min value : 112

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Test Case - 3

User Output

Enter 4 numbers :
110 103 113 109
Max value : 113
Min value : 103

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 4

User Output

Enter 4 numbers :
-34 -35 -24 -67
Max value : -24
Min value : -67

Test Case - 5

User Output

Enter 4 numbers :
24 28 34 16
Max value : 34
Min value : 16
03 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Enter 4 numbers :

Max value : 574


Min value : 547
564 547 574 563
User Output
Exp. Name: Find out the electricity bill Date: 2024-09-
S.No: 15

13 :oN egaP
charges 26

Aim:
An electricity board charges the following rates for the use of electricity:

2 Q 4 5 A 1 9 B 4 2 : DI
• If units are less than or equal to 200, then the charge is calculated as 80 paise per
unit.
• If units are less than or equal to 300, then the charge is calculated as 90 paise per
unit.
• If units are beyond 300, then the charge is calculated as 1 Rupee per unit.

All users are charged a minimum of Rs. 100 as a meter charge even though the amount
calculated is less than Rs. 100.

If the total amount charged is greater than Rs. 400, then an additional surcharge of 15%

D- B S C & DI A- 8 2 0 2- 4 2 0 2
of the total amount is charged.

Write a C program to read the name of the user, and the number of units consumed and
print out the charges as shown in the sample test cases.

Note: Print the amount charged up to 2 decimal places (actual amount, surcharges,
amount to be paid).
Source Code:

)suomonotuA( egelloC gnireenignE RKRS


electricityBillCharges.c
#include<stdio.h>

23 :oN egaP
int main()
{
char a[5];
printf("Enter customer name: ");
scanf("%s",a);

2 Q 4 5 A 1 9 B 4 2 : DI
float s,c,A;
int d;
printf("Units consumed: ");
scanf("%d",&d);
printf("Customer name: %s\n",a);
printf("Units consumed: %d\n",d);
if(d<=200)
{
s=(d*80)/100.0;
printf("Amount charged: %.2f\n",s);
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
else if((d>200)&&(d<=300))
{
s=(d*90)/100;
printf("Amount charged: %.2f\n",s);
}
else if(d>300)
{
s=d*1;
printf("Amount charged: %.2f\n",s);

)suomonotuA( egelloC gnireenignE RKRS


}
if(d>400)
{
c=d*0.15;
printf("Surcharges: %.2f\n",c);
}
else{
printf("Surcharges: 0.00\n");
}
if (d<100)
{
printf("Amount to be paid: 100.00\n");
}
else if(d>100)
{
A=s+c;
printf("Amount to be paid: %.2f\n",A);
}
}
Execution Results - All test cases have succeeded!

33 :oN egaP
Test Case - 1

User Output

Enter customer name:

2 Q 4 5 A 1 9 B 4 2 : DI
John
Units consumed:
78
Customer name: John
Units consumed: 78
Amount charged: 62.40
Surcharges: 0.00
Amount to be paid: 100.00

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Test Case - 2

User Output

Enter customer name:


Rosy
Units consumed:
325
Customer name: Rosy

)suomonotuA( egelloC gnireenignE RKRS


Units consumed: 325
Amount charged: 325.00
Surcharges: 0.00
Amount to be paid: 325.00

Test Case - 3

User Output

Enter customer name:


Amar
Units consumed:
801
Customer name: Amar
Units consumed: 801
Amount charged: 801.00
Surcharges: 120.15
Amount to be paid: 921.15
Test Case - 4

43 :oN egaP
User Output

Enter customer name:


Raman
Units consumed:

2 Q 4 5 A 1 9 B 4 2 : DI
300
Customer name: Raman
Units consumed: 300
Amount charged: 270.00
Surcharges: 0.00
Amount to be paid: 270.00

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: C program to find roots and Date: 2024-09-
S.No: 16

53 :oN egaP
nature of quadratic equation. 24

Aim:
Write a C program to find the roots of a quadratic equation, given its coefficients.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

quad.c

#include<stdio.h>
#include<math.h>
int main()
{
double a,b,c,root1,root2,d,realpart,imaginarypart;
printf("Enter coefficients a, b and c: ");
scanf("%lf%lf%lf",&a,&b,&c);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
d=(b*b)-4*a*c;
if(d>0)
{
root1=((-b)+sqrt(d))/2*a;
root2=((-b)-sqrt(d))/2*a;
printf("root1 =%.2lf and root2 = %.2lf\n",root1,root2);
}
else if(d==0)
{

)suomonotuA( egelloC gnireenignE RKRS


root1=root2=-b/(2*a);
printf("root1=.%.2lf and root2 = %.2lf\n",root1,root2);
}
else{
realpart = -b/(2*a);
imaginarypart=sqrt(-d)/(2*a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2lf-
%.2lfi",realpart,imaginarypart,realpart,imaginarypart);
}
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter coefficients a, b and c:


379
root1 = -1.17+1.28i and root2 = -1.17-1.28i

63 :oN egaP
Test Case - 2

User Output

2 Q 4 5 A 1 9 B 4 2 : DI
Enter coefficients a, b and c:
886
root1 = -0.50+0.71i and root2 = -0.50-0.71i

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Date: 2024-09-
S.No: 17 Exp. Name: Simulate a basic calculator

73 :oN egaP
26

Aim:
Write a program to perform basic calculator operations [+, -, *, /] of two integers a and b

2 Q 4 5 A 1 9 B 4 2 : DI
using switch statement.

Constraints:
• 10-4 <= a,b = 104
• operations allowed are +, -, *, /
• "/" divisibility will perform integer division operation.

Input Format: The first line of the input consists of an integer which corresponds to a,
character which corresponds to the operator and an integer which corresponds to b.

Output format: Output consists of result after performing mentioned operation (a

D- B S C & DI A- 8 2 0 2- 4 2 0 2
operation b).

Instruction: To run your custom test cases strictly map your input and output layout with
the visible test cases.
Source Code:

calculator.c

#include<stdio.h>

)suomonotuA( egelloC gnireenignE RKRS


int main()
{
int a,b;
char c;
scanf("%d",&a);
scanf("%c",&c);
scanf("%d",&b);
switch(c)
{
case'+': printf("%d",a+b);break;
case'-': printf("%d",a-b);break;
case'*': printf("%d",a*b);break;
case'/': printf("%d",a/b);break;

}
}

Execution Results - All test cases have succeeded!


Test Case - 1

83 :oN egaP
User Output

36-31
5

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 2

User Output

89/45
1

Test Case - 3

D- B S C & DI A- 8 2 0 2- 4 2 0 2
User Output

13+1000
1013

Test Case - 4

User Output

)suomonotuA( egelloC gnireenignE RKRS


25*500
12500
Exp. Name: Write a program to find leap Date: 2024-09-
S.No: 18

93 :oN egaP
year or not 26

Aim:
Lucy is celebrating her 15th birthday. Her father promised her that he will buy her a new

2 Q 4 5 A 1 9 B 4 2 : DI
computer on her birthday if she solves the question asked by him.

He asks Lucy to find whether the year on which she had born is leap year or not.

Help her to solve this puzzle so that she celebrates her birthday happily. If her birth year
is 2016 and it is a leap year display 2016 is a leap year.? Else display 2016 is not a leap
year and check with other leap year conditions.
Source Code:

leapYear.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
{
printf("%d is a leap year",year);

)suomonotuA( egelloC gnireenignE RKRS


}
else{
printf("%d is not a leap year",year);
}
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

1900
1900 is not a leap year

Test Case - 2
04 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 3

1995 is not a leap year


2004 is a leap year
User Output

User Output
2004

1995
Date: 2024-09-
S.No: 19 Exp. Name: Factorial of a given number

14 :oN egaP
24

Aim:
Write a C program to find the factorial of a given number

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

factorialOfInt.c

#include<stdio.h>
int main()
{
int i,factorial=1,n;
printf("Integer: ");
scanf("%d",&n);
for(i=1;i<=n;i++)

D- B S C & DI A- 8 2 0 2- 4 2 0 2
{
factorial=factorial*i;
}
printf("Factorial: %d\n",factorial);
}

Execution Results - All test cases have succeeded!

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 1

User Output

Integer:
5
Factorial: 120

Test Case - 2

User Output

Integer:
4
Factorial: 24
Exp. Name: C program to determine Date: 2024-09-
S.No: 20

24 :oN egaP
whether a given number is prime or not. 24

Aim:
Write the C program to determine whether a given number is prime or not.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

Prime.c

#include<stdio.h>
int main()
{
int n,i,temp=0;
printf("Enter a number: ");
scanf("%d",&n);
for(i=2;i<=n/2;i++)

D- B S C & DI A- 8 2 0 2- 4 2 0 2
{
if(n%i==0)
{
temp++;
break;
}
}
if(temp==0&&n!=1)
{

)suomonotuA( egelloC gnireenignE RKRS


printf("%d is a prime number\n",n);
}
else{
printf("%d is not a prime number\n",n);
}
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter a number:
9
9 is not a prime number
34 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 2

11 is a prime number
Enter a number:
User Output

11
Exp. Name: Compute sine and cos series Date: 2024-10-
S.No: 21

44 :oN egaP
using taylor series 15

Aim:
Write a C program to compute the sine and cosine series using the Taylor series.

2 Q 4 5 A 1 9 B 4 2 : DI
Taylor series:

sin x = x - (x3/3!) + (x5/5!) - (x7/7!) + .....

cos x = 1 - (x2/2!) + (x4/4!) - (x6/6!) + ....

Note: Print the result up to 4 decimal places. Use the double data type for all variables
except for the number of terms in the series, which should be an integer. Additionally,
initialize the variables that will store the results of the sine and cosine series to 0.0 at the
beginning.

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Source Code:

taylor.c

#include<stdio.h>
#include<math.h>
void main()
{
int terms,fact=1;

)suomonotuA( egelloC gnireenignE RKRS


float x,term1=1,term2=1,cosine,sine;
printf("angle in radians: ");
scanf ("%f",&x);
printf("number of terms in the series: ");
scanf("%d",&terms);
sine=x;
cosine=1;
for(int i=1;i<terms;i++)
{
term1=pow(-1,i)*pow(x,2*i);
fact *= (2*i);
cosine += term1/fact;
term2=pow(-1,i)*pow(x,2*i+1);
fact *=(2*i+1);
sine +=term2/fact;
}
printf("Sine = %.4f\n",sine);
printf("Cosine = %.4f\n",cosine);
}
Execution Results - All test cases have succeeded!

54 :oN egaP
Test Case - 1

User Output

angle in radians:

2 Q 4 5 A 1 9 B 4 2 : DI
0.5
number of terms in the series:
3
Sine = 0.4794
Cosine = 0.8776

Test Case - 2

User Output

D- B S C & DI A- 8 2 0 2- 4 2 0 2
angle in radians:
0.6
number of terms in the series:
5
Sine = 0.5646
Cosine = 0.8253

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Check given number is Date: 2024-09-
S.No: 22

64 :oN egaP
palindrome or not 24

Aim:
Write an C program to check given number is palindrome or not

2 Q 4 5 A 1 9 B 4 2 : DI
Input Format:
• Single Line: An integer value representing the number to be checked for
palindrome status.

Output Format:
• Single Line: A message indicating whether the number is a palindrome or not. The
format of the message will be:
• "[number] is a palindrome." if the number is a palindrome.
• "[number] is not a palindrome." if the number is not a palindrome.
Source Code:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
palindrome.c

#include<stdio.h>
int main()
{
int n,r,a,sum=0;
scanf("%d",&n);
a=n;

)suomonotuA( egelloC gnireenignE RKRS


while (n>0)
{
r=n%10;
n=n/10;
sum=sum*10+r;
}
if (sum==a)
{
printf("%d is a palindrome.\n",a);
}
else{
printf("%d is not a palindrome.\n",a);
}
}

Execution Results - All test cases have succeeded!


74 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 1

Test Case - 2

143 is not a palindrome.


121 is a palindrome.
User Output

User Output
121

143
Date: 2024-09-
S.No: 23 Exp. Name: Pyramid with numbers

84 :oN egaP
26

Aim:
Write a program to print a pyramid of numbers separated by spaces for the given

2 Q 4 5 A 1 9 B 4 2 : DI
number of rows.

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

Enter number of rows :

For example, if the user gives the input as :

Enter number of rows : 3

then the program should print the result as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
1
1 2
1 2 3

Source Code:

PyramidDemo15.c

)suomonotuA( egelloC gnireenignE RKRS


#include <stdio.h>
void main() {
int n, i, j, s;
printf("Enter number of rows : ");
scanf("%d", &n);
// Fill the missing code
for(i=1;i<=n;i++)
{
for(s=1;s<=n-i;s++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
}
Execution Results - All test cases have succeeded!

94 :oN egaP
Test Case - 1

User Output

Enter number of rows :

2 Q 4 5 A 1 9 B 4 2 : DI
3
1
1 2
1 2 3

Test Case - 2

User Output

Enter number of rows :

D- B S C & DI A- 8 2 0 2- 4 2 0 2
6
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 3

User Output

Enter number of rows :


8
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
Exp. Name: Minimum and maximum in an Date: 2024-10-
S.No: 24

05 :oN egaP
array of integers. 15

Aim:
Write a C program to find the minimum and maximum in an array of integers.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

ArrayElements.c

#include <stdio.h>
void main() {
int arr[20], number, min = 0, max = 0;
scanf("%d", &number);
printf("Elements: ");
for (int i = 0; i < number; i++) {
scanf("%d", &arr[i]);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
}
/* Write your logic here to find the maximum and minimum
in the given integer array*/
min=max=arr[0];
for(int i=0;i<number;i++)
{
if(arr[i]>max) max=arr[i];
if(arr[i]<min)
min=arr[i];

)suomonotuA( egelloC gnireenignE RKRS


}
printf("Min an Max: %d and %d",min,max );
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

5
Elements:
49682
Min an Max: 2 and 9

Test Case - 2
15 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Min an Max: 216 and 216
User Output

Elements:
216
1
Exp. Name: Search for an element using Date: 2024-10-
S.No: 25

25 :oN egaP
Linear search 15

Aim:
Write a C program to check whether a given element is present in an array of elements

2 Q 4 5 A 1 9 B 4 2 : DI
using linear search. The program should prompt the user to enter the size of the array, the
elements of the array, and the element to search for. It should then output whether the
element is found, and if so, at which position in the array.

Input Format:
• Prompt the user to enter an integer n representing the size of the array (1 ≤ n ≤ 20)
as follows:
• In the next line enter n integers representing the elements of the array separated
by space.
• Next line should input an integer key representing the element to search for.

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Output Format:
• If the element is found, output: Found at position X (where X is the 0-based index
of the found element).
• If the element is not found, output: Y is not found (where Y is the key that was
searched for).

Refer to visible test cases to strictly match with input/output layout.


Source Code:

)suomonotuA( egelloC gnireenignE RKRS


SearchEle.c
#include<stdio.h>

35 :oN egaP
int main()
{
int a[10],i,size,s;
printf("Enter size: ");
scanf("%d",&size);

2 Q 4 5 A 1 9 B 4 2 : DI
printf("Enter %d element: ",size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
printf("Enter search element: ");
scanf("%d",&s);
i=0;
while((i<size)&&(a[i]!=s))
i++;
if(i==size)
printf("%d is not found\n",s);
else

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Found at position %d\n",i);
}

Execution Results - All test cases have succeeded!

Test Case - 1

)suomonotuA( egelloC gnireenignE RKRS


User Output

Enter size:
6
Enter 6 element:
248135
Enter search element:
6
6 is not found

Test Case - 2

User Output

Enter size:
6
Enter 6 element:
248135
2
Found at position 0

45 :oN egaP
Test Case - 3

User Output

2 Q 4 5 A 1 9 B 4 2 : DI
Enter size:
6
Enter 6 element:
248135
Enter search element:
9
9 is not found

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: C program to reverse an Date: 2024-10-
S.No: 26

55 :oN egaP
array. 08

Aim:
Write a C program to reverse the elements an array of integers.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

reverseArray.c

#include<stdio.h>
int main()
{
int a[10],i,n;
printf("Enter no of elements: ");
scanf("%d",&n);
printf("Enter elements: ");

D- B S C & DI A- 8 2 0 2- 4 2 0 2
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The reversed array: ");
for(i=n-1;i>=0;i--)
{
printf("%d ",a[i]);
}

)suomonotuA( egelloC gnireenignE RKRS


}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter no of elements:
5
Enter elements:
34124
The reversed array: 4 2 1 4 3

Test Case - 2

User Output
65 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
The reversed array: 9 2 88 33 77 1 5 2
Enter no of elements:

2 5 1 77 33 88 2 9
Enter elements:
8
Exp. Name: 2’s complement of a given Date: 2024-11-
S.No: 27

75 :oN egaP
Binary number 19

Aim:
Write a C program to find 2’s complement of a given binary number.

2 Q 4 5 A 1 9 B 4 2 : DI
Note: The binary input should be separated by a space.
Source Code:

twosComplement.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
#include<stdio.h>

85 :oN egaP
int main()
{
int n,i;
int a[10];
printf("Enter size: ");

2 Q 4 5 A 1 9 B 4 2 : DI
scanf("%d",&n);
printf("Enter %d bit binary number: ",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("2's complement: ");
for(i=0;i<n;i++)
{
if(a[i]==0){
a[i]=1;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
}
else{
a[i]=0;
}
}
for(i=n-1;i>=0;i--)
{
if(a[i]==0){
a[i]=1;

)suomonotuA( egelloC gnireenignE RKRS


break;
}
else{
a[i]=0;
}
}
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}

Execution Results - All test cases have succeeded!

Test Case - 1
User Output

95 :oN egaP
Enter size:
5
Enter 5 bit binary number:
10010

2 Q 4 5 A 1 9 B 4 2 : DI
2's complement: 0 1 1 1 0

Test Case - 2

User Output

Enter size:
6
Enter 6 bit binary number:
100011

D- B S C & DI A- 8 2 0 2- 4 2 0 2
2's complement: 0 1 1 1 0 1

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Eliminate duplicate elements Date: 2024-11-
S.No: 28

06 :oN egaP
in an array 19

Aim:
Write a C program to eliminate duplicate elements of an array.

2 Q 4 5 A 1 9 B 4 2 : DI
Input Format:
• First Line: An integer n representing the size of the array.
• Second Line: n integers representing the elements of the array.

Output Format:
• Single Line: A space-separated list of the unique elements of the array after
duplicates have been removed.
Source Code:

eliminateDuplicates.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
#include<stdio.h>

16 :oN egaP
int main()
{
int n,i,j,k;
int a[10];
printf("Enter size: ");

2 Q 4 5 A 1 9 B 4 2 : DI
scanf("%d",&n);
printf("Enter %d elements: ",n);
for(i=0;i<n;i++)
{
scanf("%d ",&a[i]);
}
printf("After eliminating duplicates: ");
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{

D- B S C & DI A- 8 2 0 2- 4 2 0 2
if(a[i]==a[j]){
for(k=j;k<n-
1;k++){

a[k]=a[k+1];
}
n--;
j--;
}

)suomonotuA( egelloC gnireenignE RKRS


}
}
for(i=0;i<n;i++)
{
printf("%d ", a[i]);
}
printf("\n");
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter size:
5
Enter 5 elements:
12123
After eliminating duplicates: 1 2 3

26 :oN egaP
Test Case - 2

User Output

2 Q 4 5 A 1 9 B 4 2 : DI
Enter size:
5
Enter 5 elements:
11 13 11 12 13
After eliminating duplicates: 11 13 12

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Date: 2024-10-
S.No: 29 Exp. Name: Addition of Two Matrices

36 :oN egaP
01

Aim:
Write a C program to perform the addition of two matrices each with the size m × n .

2 Q 4 5 A 1 9 B 4 2 : DI
Input Format:
• First, enter the number of rows and columns (two integers separated by space).
• Then, enter the elements of the first matrix (m * n integers).
• Finally, enter the elements of the second matrix (m * n integers).

Output Format:
• Print the resulting matrix after addition, formatted as a matrix.

Note: The addition of two matrices can only be done when the dimensions of both

D- B S C & DI A- 8 2 0 2- 4 2 0 2
matrices are the same, so we are taking the same dimensions for both matrices.
Source Code:

addTwoMatrices.c

)suomonotuA( egelloC gnireenignE RKRS


#include<stdio.h>

46 :oN egaP
int main()
{
int a[10][10],b[10][10],c[10][10],i,j,rows,columns;
printf("Enter no of rows, columns: ");
scanf("%d%d",&rows,&columns);

2 Q 4 5 A 1 9 B 4 2 : DI
printf("Elements of matrix 1: ");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Elements of matrix 2: ");
for(i=0;i<rows;i++)
{

D- B S C & DI A- 8 2 0 2- 4 2 0 2
for(j=0;j<columns;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{

)suomonotuA( egelloC gnireenignE RKRS


c[i][j]=a[i][j]+b[i][j];
}
}
printf("Addition of matrices:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<columns;j++)
{
printf("%d ",c[i][j]);
}
printf("\n");
}
}

Execution Results - All test cases have succeeded!

Test Case - 1
User Output

56 :oN egaP
Enter no of rows, columns:
12
Elements of matrix 1:
12

2 Q 4 5 A 1 9 B 4 2 : DI
Elements of matrix 2:
98
Addition of matrices:
10 10

Test Case - 2

User Output

Enter no of rows, columns:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
23
Elements of matrix 1:
123456
Elements of matrix 2:
987654
Addition of matrices:
10 10 10
10 10 10

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Multiplication of Two Date: 2024-10-
S.No: 30

66 :oN egaP
Matrices 15

Aim:
Write a C program to find the multiplication of two matrices of size r × c.

2 Q 4 5 A 1 9 B 4 2 : DI
Input Format:
• First line contains an integer r and an integer c, representing the number of rows
and columns
• Next r rows contains c number of integers representing the elements of the
matrix1
• Repeat the Same for matrix2

Output Format:
• Prints the matrix1 and matrix2 and finally the result of multiplication of both the
matrices

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Refer to the sample test cases for better understanding

Sample Input:
2 2
11 22
33 44
2 2
11 22

)suomonotuA( egelloC gnireenignE RKRS


33 44

Sample Output:
matrix1:
11 22
33 44
matrix2:
11 22
33 44
result:
847 1210
1815 2662

Note: Add new line char \n at the end of each line in the output.
Refer to visible test cases for better understanding
Source Code:

matrixMul.c
#include<stdio.h>

76 :oN egaP
int main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,r1,c1,r2,c2;
printf("no of rows, columns of matrix1: ");
scanf("%d%d",&r1,&c1);

2 Q 4 5 A 1 9 B 4 2 : DI
printf("matrix1 elements:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("no of rows, columns of matrix2: ");
scanf("%d%d",&r2,&c2);
printf("matrix2 elements:\n");

D- B S C & DI A- 8 2 0 2- 4 2 0 2
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Given matrix1:\n");
for(i=0;i<r1;i++)

)suomonotuA( egelloC gnireenignE RKRS


{
for(j=0;j<c1;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("Given matrix2:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
if(c1==r2)
{
printf("Multiplication of two matrices:\n");
for(i=0;i<r1;i++)
{

86 :oN egaP
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<r2;k++)
{

2 Q 4 5 A 1 9 B 4 2 : DI
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ",c[i][j]);
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("\n");
}
}
else{
printf("Multiplication not possible\n");
}
}

)suomonotuA( egelloC gnireenignE RKRS


Execution Results - All test cases have succeeded!

Test Case - 1

User Output

22
11 22
33 44
22
11 22
33 44
matrix1:
11 22
33 44
matrix2:
33 44
result:

96 :oN egaP
847 1210
1815 2662

Test Case - 2

2 Q 4 5 A 1 9 B 4 2 : DI
User Output

33
123
456
789
23
123
456

D- B S C & DI A- 8 2 0 2- 4 2 0 2
matrix1:
1 2 3
4 5 6
7 8 9
matrix2:
1 2 3
4 5 6

)suomonotuA( egelloC gnireenignE RKRS


Multiplication not possible
Exp. Name: Write a C program to Sort Date: 2024-10-
S.No: 31

07 :oN egaP
given elements using Bubble sort 15

Aim:
Develop an algorithm, implement and execute a C program that reads n integer numbers

2 Q 4 5 A 1 9 B 4 2 : DI
and arrange them in ascending order using Bubble Sort.
Source Code:

Lab7.c

#include<stdio.h>
int main()
{
int i,j,n,size,temp;
int arr[20];
printf("Elements: ");

D- B S C & DI A- 8 2 0 2- 4 2 0 2
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("Before sorting: ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);

)suomonotuA( egelloC gnireenignE RKRS


}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("\nAfter sorting: ");
for(i=0;i<n;i++)
{
printf("%d ",arr[i]);
}
printf("\n");
}
Execution Results - All test cases have succeeded!

17 :oN egaP
Test Case - 1

User Output

2 Q 4 5 A 1 9 B 4 2 : DI
Elements:
44 22 66 11
Before sorting: 44 22 66 11
After sorting: 11 22 44 66

Test Case - 2

User Output

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Elements:
92716
Before sorting: 9 2 7 1 6
After sorting: 1 2 6 7 9

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Concatenate two given
Date: 2024-11-

27 :oN egaP
S.No: 32 strings without using string library
19
functions

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a program to concatenate two given strings without using string library
functions.

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

string1 :

For example, if the user gives the input as:

string1 : ILove

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Next, the program should print the message on the console as:

string2 :

For example, if the user gives the input as:

string2 : Coding

)suomonotuA( egelloC gnireenignE RKRS


then the program should print the result as:

concatenated string = ILoveCoding

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

Program605.c
#include<stdio.h>

37 :oN egaP
int main()
{
char a[20],b[40];
int j,i;
printf("string1 : ");

2 Q 4 5 A 1 9 B 4 2 : DI
scanf("%s",a);
printf("string2 : ");
scanf("%s",b);
for(j=0;a[j]!='\0';j++);
for(i=0;b[i]!='\0';j++,i++)
{
a[j]=b[i];
}
a[j]='\0';
printf("concatenated string = %s\n",a);
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

)suomonotuA( egelloC gnireenignE RKRS


string1 :
ILove
string2 :
Coding
concatenated string = ILoveCoding

Test Case - 2

User Output

string1 :
1234
string2 :
567
concatenated string = 1234567
Exp. Name: Reverse the given string Date: 2024-11-
S.No: 33

47 :oN egaP
without using the library functions 19

Aim:
Write a program to reverse the given string without using the library functions.

2 Q 4 5 A 1 9 B 4 2 : DI
At the time of execution, the program should print the message on the console as:

Enter a string :

For example, if the user gives the input as:

Enter a string : Dallas

then the program should print the result as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Reverse string : sallaD

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

Program609.c

#include<stdio.h>
int main()

)suomonotuA( egelloC gnireenignE RKRS


{
char a[20];
int i,len=0;
printf("Enter a string : ");
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
len++;
}
printf("Reverse string : ");
for(i=len-1;i>=0;i--)
{
printf("%c",a[i]);
}
printf("\n");
}

Execution Results - All test cases have succeeded!


Test Case - 1

57 :oN egaP
User Output

Enter a string :
Dallas
Reverse string : sallaD

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 2

User Output

Enter a string :
CodeTantra
Reverse string : artnaTedoC

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Write a C program to find
Date: 2024-11-

67 :oN egaP
S.No: 34 Sum of array elements by allocating
28
memory using malloc() function

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a program to find the sum of n elements by allocating memory by using malloc()
function.

Note: Write the functions allocateMemory(), read1() and sum() in UsingMalloc.c


Source Code:

SumOfArray1.c

#include <stdio.h>
#include <stdlib.h>
#include "UsingMalloc.c"

D- B S C & DI A- 8 2 0 2- 4 2 0 2
void main() {
int *p, n, i;
printf("Enter n value : ");
scanf("%d", &n);
p = allocateMemory(n);
printf("Enter %d values : ", n);
read1(p, n);
printf("The sum of given array elements : %d\n", sum(p,

)suomonotuA( egelloC gnireenignE RKRS


n));
}

UsingMalloc.c
int *allocateMemory(int n)

77 :oN egaP
{
int *p;
p=malloc(n * sizeof(int));
return p;
}

2 Q 4 5 A 1 9 B 4 2 : DI
void read1(int *p,int n)
{
for(int i=0;i<n;i++)
{
scanf("%d",(p+i));
}
}
int sum(int *p,int n)
{
int total=0;
for(int i=0;i<n;i++)

D- B S C & DI A- 8 2 0 2- 4 2 0 2
{
total+=*(p+i);
}
return total;
}

Execution Results - All test cases have succeeded!

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 1

User Output

Enter n value :
3
Enter 3 values :
10 20 30
The sum of given array elements : 60

Test Case - 2

User Output

Enter n value :
4
Enter 4 values :
-5 -6 -4 -2
Exp. Name: Write a program to find Total
Date: 2024-11-

87 :oN egaP
S.No: 35 and Average gained by Students in a
28
Section using Array of Structures

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to find out the total and average marks gained by the students in a
section using array of structures.

Note: Consider that regdno, marks of 3 subjects, total and average are the members of a
structure and make sure to provide the int value for number of students which are
lessthan 60

Sample Input and Output:


Enter number of students : 3
Enter regdno, three subjects marks of student-0: 101 56 78 76
Enter regdno, three subjects marks of student-1: 201 76 89 91

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter regdno, three subjects marks of student-2: 301 46 57 61
Student-0 Regdno = 101 Total marks = 210 Average marks = 70.000000
Student-1 Regdno = 201 Total marks = 256 Average marks = 85.333336
Student-2 Regdno = 301 Total marks = 164 Average marks = 54.666668
Source Code:

ArrayOfStructures2.c

)suomonotuA( egelloC gnireenignE RKRS


#include <stdio.h>

97 :oN egaP
struct student {
int regdno;
int marks[3];
// Write the members of structure
};

2 Q 4 5 A 1 9 B 4 2 : DI
void main() {
struct student s[60];
int i,n,total;
float average;
printf("Enter number of students : ");
scanf("%d", &n);
for (i=0;i<n;i++) { // Complete the code in for
printf("Enter regdno, three subjects marks of
student-%d: ", i);
scanf("%d %d %d
%d",&s[i].regdno,&s[i].marks[0],&s[i].marks[1],&s[i].marks[2]);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
// Read regdno and 3 subjects marks
}
for (i=0;i<n;i++) { // Complete the code in for
total=s[i].marks[0]+s[i].marks[1]+s[i].marks[2];
average=total/3.0;// Find Total and Average
printf("Student-%d Regdno = %d\tTotal marks =
%d\tAverage marks = %f\n",i,s[i].regdno,total,average ); // Fill
the code in printf()
}

)suomonotuA( egelloC gnireenignE RKRS


}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter number of students :


3
Enter regdno, three subjects marks of student-0:
101 56 78 76
Enter regdno, three subjects marks of student-1:
201 76 89 91
Enter regdno, three subjects marks of student-2:
301 46 57 61
Student-1 Regdno = 201 Total marks = 256 Average marks =
85.333336

08 :oN egaP
Student-2 Regdno = 301 Total marks = 164 Average marks =
54.666668

Test Case - 2

2 Q 4 5 A 1 9 B 4 2 : DI
User Output

Enter number of students :


10
Enter regdno, three subjects marks of student-0:
501 23 45 67
Enter regdno, three subjects marks of student-1:
502 78 65 76
Enter regdno, three subjects marks of student-2:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
503 99 87 67
Enter regdno, three subjects marks of student-3:
504 89 78 82
Enter regdno, three subjects marks of student-4:
505 37 59 76
Enter regdno, three subjects marks of student-5:
506 78 59 67

)suomonotuA( egelloC gnireenignE RKRS


Enter regdno, three subjects marks of student-6:
507 92 72 82
Enter regdno, three subjects marks of student-7:
508 45 47 48
Enter regdno, three subjects marks of student-8:
509 55 52 59
Enter regdno, three subjects marks of student-9:
510 62 61 66
Student-0 Regdno = 501 Total marks = 135 Average marks =
45.000000
Student-1 Regdno = 502 Total marks = 219 Average marks =
73.000000
Student-2 Regdno = 503 Total marks = 253 Average marks =
84.333336
Student-3 Regdno = 504 Total marks = 249 Average marks =
83.000000
Student-4 Regdno = 505 Total marks = 172 Average marks =
57.333332
Student-6 Regdno = 507 Total marks = 246 Average marks =
82.000000

18 :oN egaP
Student-7 Regdno = 508 Total marks = 140 Average marks =
46.666668
Student-8 Regdno = 509 Total marks = 166 Average marks =
55.333332
Student-9 Regdno = 510 Total marks = 189 Average marks =

2 Q 4 5 A 1 9 B 4 2 : DI
63.000000

Test Case - 3

User Output

Enter number of students :


5
Enter regdno, three subjects marks of student-0:
101 76 78 73

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter regdno, three subjects marks of student-1:
102 89 57 68
Enter regdno, three subjects marks of student-2:
103 77 67 59
Enter regdno, three subjects marks of student-3:
104 37 47 52
Enter regdno, three subjects marks of student-4:

)suomonotuA( egelloC gnireenignE RKRS


105 88 47 69
Student-0 Regdno = 101 Total marks = 227 Average marks =
75.666664
Student-1 Regdno = 102 Total marks = 214 Average marks =
71.333336
Student-2 Regdno = 103 Total marks = 203 Average marks =
67.666664
Student-3 Regdno = 104 Total marks = 136 Average marks =
45.333332
Student-4 Regdno = 105 Total marks = 204 Average marks =
68.000000
Exp. Name: Write a Program to enter n
Date: 2024-12-

28 :oN egaP
S.No: 36 students data using calloc() and display
03
Failed Students List

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to enter n students' data using calloc() and display the students list.

Note: If marks are less than 35 in any subject, the student will fail
Source Code:

FailedList.c

#include <stdio.h>
#include <stdlib.h>
struct student {
int roll;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
int marks[6], sum;
float avg;
};
#include "FailedList1.c"
void main() {
struct student *s;
int i, n;
printf("Enter the number of students : ");
scanf("%d", &n);

)suomonotuA( egelloC gnireenignE RKRS


s = allocateMemory(s, n);
read1(s, n);
calculateMarks(s, n);
displayFailedList(s, n);
}

FailedList1.c
struct student* allocateMemory(struct student *s, int n) {

38 :oN egaP
s=(struct student*)calloc(n,sizeof(struct student));
return s;
}

void read1(struct student *s, int n) {

2 Q 4 5 A 1 9 B 4 2 : DI
int i;
for(i=0;i<n;i++){
printf("Enter the details of student -
%d\n",i+1);
printf("Enter the roll number : ");
scanf("%d",&s[i].roll);
printf("Enter 6 subjects marks : ");

scanf("%d%d%d%d%d%d",&s[i].marks[0],&s[i].marks[1],&s[i].marks[2],&s[i].marks[3],&s[i].ma
}
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
void calculateMarks(struct student *s, int n) {
int i,j;
for(i=0;i<n;i++){
for(j=0;j<6;j++)
s[i].sum=s[i].sum+s[i].marks[j];
}
for(i=0;i<n;i++){
s[i].avg=(float)s[i].sum/6;}
}

)suomonotuA( egelloC gnireenignE RKRS


void displayFailedList(struct student *s, int n) {
int i;
printf("RollNo\tTotalMarks\tAverageMarks\tStatus\n");
for (i = 0; i < n; i++) {
printf("%d\t", s[i].roll); // Fill the missing
code
printf("%d\t", s[i].sum); // Fill the missing
code
printf("%f\t", s[i].avg); // Fill the missing
code
if (s[i].marks[0]<35||s[i].marks[1]
<35||s[i].marks[2]<35||s[i].marks[3]<35||s[i].marks[4]
<35||s[i].marks[5]<35) // Fill the missing code
printf("Fail");
else
printf("Pass");
printf("\n");
}
}
Execution Results - All test cases have succeeded!

48 :oN egaP
Test Case - 1

User Output

Enter the number of students :

2 Q 4 5 A 1 9 B 4 2 : DI
3
Enter the details of student - 1
Enter the roll number :
101
Enter 6 subjects marks :
45 67 58 36 59 63
Enter the details of student - 2
Enter the roll number :
102

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter 6 subjects marks :
34 56 98 39 78 89
Enter the details of student - 3
Enter the roll number :
103
Enter 6 subjects marks :
35 67 89 98 76 56
RollNo TotalMarks AverageMarks Status

)suomonotuA( egelloC gnireenignE RKRS


101 328 54.666668 Pass
102 394 65.666664 Fail
103 421 70.166664 Pass

Test Case - 2

User Output

Enter the number of students :


2
Enter the details of student - 1
Enter the roll number :
1001
Enter 6 subjects marks :
26 57 68 67 67 65
Enter the details of student - 2
Enter the roll number :
1002
58 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Status
AverageMarks
Fail
Pass
58.333332
72.500000
TotalMarks
350
435
RollNo
1001
1002
Exp. Name: Write a C program to find
Date: 2024-11-

68 :oN egaP
S.No: 37 Total Marks of a Student using
28
Command-line arguments

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to read student name and 3 subjects marks from the command line
and display the student details along with total.

Sample Input and Output - 1:

If the arguments passed as $./TotalMarksArgs.c Sachin 67 89 58 ,


then the program should print the output as:
Cmd Args : Sachin 67 89 58
Student name : Sachin
Subject-1 marks : 67
Subject-1 marks : 89

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Subject-1 marks : 58
Total marks : 214

Sample Input and Output - 2:

If the arguments passed as $./TotalMarksArgs.c Johny 45 86 57 48 ,


then the program should print the output as:
Cmd Args : Johny 45 86 57 48

)suomonotuA( egelloC gnireenignE RKRS


Arguments passed through command line are not equal to 4

Hint : atoi() is a library function that converts string to integer. When program gets the
input from command line, string values transfer in the program, we have to convert them
to integers. atoi() is used to return the integer of the string arguments.
Source Code:

TotalMarksArgs.c
#include<stdio.h>

78 :oN egaP
#include<stdlib.h>
int main(int argc,char*argv[])
{
if(argc!=5)
printf("Arguments passed through command line are

2 Q 4 5 A 1 9 B 4 2 : DI
not equal to 4\n",argc);
else
{
printf("Student name : %s\n",argv[1]);
printf("Subject-1 marks : %s\n",argv[2]);
printf("Subject-2 marks : %s\n",argv[3]);
printf("Subject-3 marks : %s\n",argv[4]);
printf("Total marks :
%d\n",atoi(argv[2])+atoi(argv[3])+atoi(argv[4]));
}
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Execution Results - All test cases have succeeded!

Test Case - 1

User Output

)suomonotuA( egelloC gnireenignE RKRS


Student name : Sachin
Subject-1 marks : 67
Subject-2 marks : 89
Subject-3 marks : 58
Total marks : 214

Test Case - 2

User Output

Arguments passed through command line are not equal to 4


Exp. Name: Write a C program to Date: 2024-11-
S.No: 38

88 :oN egaP
implement realloc() 28

Aim:
Write a C program to implement realloc() .

2 Q 4 5 A 1 9 B 4 2 : DI
The process is
1. Allocate memory of an array with size 2 by using malloc()
2. Assign the values 10 and 20 to the array
3. Reallocate the size of the array to 3 by using realloc()
4. Assign the value 30 to the newly allocated block
5. Display all the 3 values
Source Code:

ProgramOnRealloc.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr = (int *)malloc(sizeof(int) * 2);
int i;
int *ptr_new;
*ptr = 10;
*(ptr + 1) = 20;

)suomonotuA( egelloC gnireenignE RKRS


ptr_new = (int*)realloc(ptr,sizeof(int)*3);
*(ptr_new+2)=30;
// Reallocate the *ptr size to 3
//Assign the value 30 to newly allocated memory
for (i = 0; i < 3; i++)
printf("%d ", *(ptr_new + i));
return 0;
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

10 20 30
Exp. Name: Write a C Program to store Date: 2024-12-
S.No: 39

98 :oN egaP
information using Structures with DMA 02

Aim:
Write a program to create a list of nodes using self-referential structure and

2 Q 4 5 A 1 9 B 4 2 : DI
print that data.

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

Enter an integer value :

For example, if the user gives the input as:

Enter an integer value : 10

Next, the program should print the message on the console as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Do u want another list (y|n) :

if the user gives the input as:

Do u want another list (y|n) : y

The input to the list is continued up to the user says n (No)

)suomonotuA( egelloC gnireenignE RKRS


For example, if the user gives the input as:

Enter an integer value : 20


Do u want another list (y|n) : y
Enter an integer value : 30
Do u want another list (y|n) : n

Finally, the program should print the result on the console as:

The elements in the single linked lists are : 10-->20-->30--


>NULL

Note: Write the functions create() and display() in CreateNodes.c .


Source Code:

StructuresWithDma.c
#include <stdio.h>

09 :oN egaP
#include <stdlib.h>
struct list {
int data;
struct list *next;
};

2 Q 4 5 A 1 9 B 4 2 : DI
#include "CreateNodes.c"
void main() {
struct list *first = NULL;
first = create(first);
printf("The elements in the single linked lists are : ");
display(first);
}

CreateNodes.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
struct list* create(struct list *first) {

19 :oN egaP
char op;
struct list *q, *temp;
do {
temp = (struct list *)malloc(sizeof(struct
list)); // Allocate memory

2 Q 4 5 A 1 9 B 4 2 : DI
printf("Enter an integer value : ");
scanf("%d",&temp->data ); // Read data
temp -> next = NULL; // Place NULL
if (first == NULL) {
first = temp; // Assign temp to the first
node
} else {
q -> next = temp; // Create a link from
the last node to new node temp
}
q = temp;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Do u want another list (y|n) : ");
scanf(" %c", &op);
} while(op == 'y' || op == 'Y');
return first;
}
void display(struct list *first) {
struct list *temp = first;
while (temp!=NULL) { // Stop the loop where temp is NULL
printf("%d-->", temp->data);

)suomonotuA( egelloC gnireenignE RKRS


temp = temp->next; // Assign next of temp to temp
}
printf("NULL\n");
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter an integer value :


10
Do u want another list (y|n) :
y
Enter an integer value :
20
y
Enter an integer value :

29 :oN egaP
30
Do u want another list (y|n) :
n
The elements in the single linked lists are : 10-->20-->30--

2 Q 4 5 A 1 9 B 4 2 : DI
>NULL

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Write a C program to
Date: 2024-12-

39 :oN egaP
S.No: 40 demonstrate the differences between
02
Structures and Unions

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to demonstrate the differences between structures and unions.

The process is
6. Create a structure student-1 with members rollno, m1, m2, m3, total of int type and
avg of float type
7. Read rollno, m1, m2 and m3 of student-1
8. Find and display total and average marks of student-1
9. Display the size of struct student-1
10. Create a union student-2 with members rollno, m1, m2, m3, total of int type and
avg of float type
11. Read rollno, m1, m2 and m3 of student-2

D- B S C & DI A- 8 2 0 2- 4 2 0 2
12. Find and display total and average marks of student-2
13. Display the size of union student-2
Sample Input and Output:
Student 1 rollno and marks: 101 76 58 67
Total and average: 201 67.000000
Student 1 struct size: 24
Student 2 rollno: 102
Student 2 marks 1: 76
Student 2 marks 2: 87

)suomonotuA( egelloC gnireenignE RKRS


Student 2 marks 3: 69
Student 2 total marks: 232
Student 2 average marks: 77.333336
Student 2 union size: 4
Source Code:

StructureAndUnion.c
#include<stdio.h>

49 :oN egaP
void main()
{
struct stdent_1
{
int rollno,m1,m2,m3,total;

2 Q 4 5 A 1 9 B 4 2 : DI
float avg;
}ss;
union student_2
{
int rollno,m1,m2,m3,total;
float avg;
}us;
int temp;
printf("Student 1 rollno and marks: ");
scanf("%d%d%d%d",&ss.rollno,&ss.m1,&ss.m2,&ss.m3);
ss.total = ss.m1+ss.m2+ss.m3;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
ss.avg = ss.total/3.0;
printf("Total and average: %d %f\n",ss.total,ss.avg);
printf("Student 1 struct size: %ld\n",sizeof(ss));
printf("Student 2 rollno: ");
scanf("%d",&us.rollno);
printf("Student 2 marks 1: ");
scanf("%d",&us.m1);
temp =us.m1;
printf("Student 2 marks 2: ");

)suomonotuA( egelloC gnireenignE RKRS


scanf("%d",&us.m2);
temp+=us.m2;
printf("Student 2 marks 3: ");
scanf("%d",&us.m3);
temp+=us.m3;
us.total=temp;
printf("Student 2 total marks: %d\n",us.total);
us.avg = temp/3.0;
printf("Student 2 average marks: %f\n",us.avg);
printf("Student 2 union size: %ld\n",sizeof(us));
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output
Student 1 rollno and marks:
101 76 58 67

59 :oN egaP
Total and average: 201 67.000000
Student 1 struct size: 24
Student 2 rollno:
102

2 Q 4 5 A 1 9 B 4 2 : DI
Student 2 marks 1:
76
Student 2 marks 2:
87
Student 2 marks 3:
69
Student 2 total marks: 232
Student 2 average marks: 77.333336
Student 2 union size: 4

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Test Case - 2

User Output

Student 1 rollno and marks:


105 66 65 68
Total and average: 199 66.333336

)suomonotuA( egelloC gnireenignE RKRS


Student 1 struct size: 24
Student 2 rollno:
106
Student 2 marks 1:
88
Student 2 marks 2:
89
Student 2 marks 3:
79
Student 2 total marks: 256
Student 2 average marks: 85.333336
Student 2 union size: 4
Exp. Name: Demonstrate left shift Date: 2024-11-
S.No: 41

69 :oN egaP
operation 29

Aim:
Write a C program to demonstrate left shift operation

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

shift.c

#include<stdio.h>
void decimaltobinary(int n)
{
int binary[1000],i,j;
if(n==0)
{
printf("0");

D- B S C & DI A- 8 2 0 2- 4 2 0 2
}
while (n>0)
{
binary[i]=n%2;
n=n/2;
i++;
}
for(j=i-1;j>=0;j--)
{

)suomonotuA( egelloC gnireenignE RKRS


printf("%d",binary[j]);
}
}
int main()
{
int n,nl,c,num;
printf("Enter an integer: ");
scanf("%d",&n);
num=n;
printf("Original value: ");
decimaltobinary(n);
printf("\nnumber of bits to left shift: ");
scanf("%d",&nl);
c=(num<<nl);
printf("After left shift: %d",c);
printf("\nBinary representation:");
decimaltobinary(c);
return 0;
}
Execution Results - All test cases have succeeded!

79 :oN egaP
Test Case - 1

User Output

Enter an integer:

2 Q 4 5 A 1 9 B 4 2 : DI
12
Original value: 1100
number of bits to left shift:
2
After left shift: 48
Binary representation:110000

Test Case - 2

D- B S C & DI A- 8 2 0 2- 4 2 0 2
User Output

Enter an integer:
5
Original value: 101
number of bits to left shift:
3
After left shift: 40
Binary representation:101000

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Copy the contents of one
Date: 2024-12-

89 :oN egaP
S.No: 42 structure variable to another structure
02
variable

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to Copy the contents of one structure variable to another structure
variable.

Let us consider a structure student, containing name, age and height fields.

Declare two structure variables to the structure student, read the contents of one
structure variable and copy the same to another structure variable, finally display the
copied data.

Note: Driver code is provided to you in the CopyStructureMain.c file. You need to fill the
missing code in CopyStructureFunctions.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Source Code:

CopyStructureMain.c

#include <stdio.h>
#include "CopyStructureFunctions.c"

int main() {
struct student s1, s2;

)suomonotuA( egelloC gnireenignE RKRS


read1(&s1);
s2 = copyStructureVariable(s1, s2);
display1(s2);
}

CopyStructureFunctions.c
struct student {

99 :oN egaP
//write the code
char name[20];
int age;
float height;
};

2 Q 4 5 A 1 9 B 4 2 : DI
void read1(struct student *p) {
printf("Enter student name, age and height: ");
// Write the code to take inputs to structure
scanf("%s%d%f",p->name,&p->age,&p->height);
}

struct student copyStructureVariable(struct student s1, struct


student s2) {
//write your code here to copy the structure
#include<string.h>

D- B S C & DI A- 8 2 0 2- 4 2 0 2
strcpy(s2.name,s1.name);
s2.age=s1.age;
s2.height=s1.height;
return s2;
}

void display1(struct student s) {


//write your code here to display the structure data
printf("Student name: %s\n",s.name);

)suomonotuA( egelloC gnireenignE RKRS


printf("Age: %d\n",s.age);
printf("Height: %f\n",s.height);

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter student name, age and height:


Yamuna 19 5.2
Student name: Yamuna
Age: 19
Height: 5.200000
Test Case - 2

001 :oN egaP


User Output

Enter student name, age and height:


Kohli 21 5.11
Student name: Kohli

2 Q 4 5 A 1 9 B 4 2 : DI
Age: 21
Height: 5.110000

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Write a C Program to find nCr Date: 2024-11-
S.No: 43

101 :oN egaP


using Factorial recursive function 26

Aim:
Draw the flowchart and write a recursive C function to find the factorial of a number, n! ,

2 Q 4 5 A 1 9 B 4 2 : DI
defined by fact(n) = 1, if n = 0. Otherwise fact(n) = n * fact(n-1).

Using this function, write a C program to compute the binomial coefficient ncr . Tabulate
the results for different values of n and r with suitable messages.

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

Enter the values of n and r :

For example, if the user gives the input as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter the values of n and r : 4 2

then the program should print the result as:

The value of 4c2 = 6

If the input is given as 2 and 5 then the program should print the result as:

)suomonotuA( egelloC gnireenignE RKRS


Enter valid input data

Note: Write the recursive function factorial() in Lab14a.c .


Source Code:

Lab14a.c

int factorial(int x)
{
if(x==0)
{
return 1;
}
else{
return x*factorial(x-1);
}
}

Lab14.c
#include <stdio.h>

201 :oN egaP


#include "Lab14a.c"
void main() {
int n, r;
printf("Enter the values of n and r : ");
scanf("%d %d", &n, &r);
if (n >= r)

2 Q 4 5 A 1 9 B 4 2 : DI
printf("The value of %dc%d = %d\n", n, r,
factorial(n) / (factorial(r) * factorial(n - r)));
else
printf("Enter valid input data\n");
}

Execution Results - All test cases have succeeded!

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Test Case - 1

User Output

Enter the values of n and r :


10 4
The value of 10c4 = 210

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 2

User Output

Enter the values of n and r :


79
Enter valid input data

Test Case - 3

User Output

Enter the values of n and r :


52
The value of 5c2 = 10
Exp. Name: Write a Program to find the Date: 2024-11-
S.No: 44

301 :oN egaP


Length of a String 26

Aim:
Write a C program to find the length of a given string.

2 Q 4 5 A 1 9 B 4 2 : DI
Sample Input and Output - 1:

Enter the string : CodeTantra


Length of CodeTantra : 10

Source Code:

StrLength.c

#include <stdio.h>

D- B S C & DI A- 8 2 0 2- 4 2 0 2
#include "StrLength1.c"
void main() {
char str[30];
printf("Enter the string : ");
scanf("%s", str);
printf("Length of %s : %d\n", str, myStrLen(str));
}

)suomonotuA( egelloC gnireenignE RKRS


StrLength1.c

#include<stdio.h>
int myStrLen(char*str)
{
int length=0;
while(str[length]!='\0')
{
length++;
}
return length;
}

Execution Results - All test cases have succeeded!

Test Case - 1
Enter the string :
CodeTantra

401 :oN egaP


Length of CodeTantra : 10

Test Case - 2

2 Q 4 5 A 1 9 B 4 2 : DI
User Output

Enter the string :


IndoUsUk
Length of IndoUsUk : 8

Test Case - 3

User Output

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter the string :
MalayalaM
Length of MalayalaM : 9

Test Case - 4

User Output

)suomonotuA( egelloC gnireenignE RKRS


Enter the string :
Oh!MyGod
Length of Oh!MyGod : 8
Date: 2024-12-
S.No: 45 Exp. Name: Transpose using functions.

501 :oN egaP


02

Aim:
Write a C program to print the transpose of a matrix using functions.

2 Q 4 5 A 1 9 B 4 2 : DI
Input Format
• First Line: The user will input the number of rows for the matrix.
• Second Line: The user will input the number of columns for the matrix.
• Subsequent Lines: The user will input the matrix elements row by row.

Output Format
• First Line: The program will print the matrix in its original form.
• Second Line: The program will print the transpose of the matrix.
Source Code:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
transpose.c

)suomonotuA( egelloC gnireenignE RKRS


#include <stdio.h>

601 :oN egaP


int rows=5, cols=5;
//write your code..
void readMatrix(int matrix[rows][cols])
{
int i,j;
printf("Elements:\n");

2 Q 4 5 A 1 9 B 4 2 : DI
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
scanf("%d",&matrix[i]
[j]);
}
}
}
void printMatrix(int matrix[rows][cols])

D- B S C & DI A- 8 2 0 2- 4 2 0 2
{
int i,j;
printf("Matrix:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
printf("%d ",matrix[i]
[j]);

)suomonotuA( egelloC gnireenignE RKRS


}
printf("\n");
}
}
void transposeMatrix(int matrix[rows][cols])
{
int i,j,tem,b[20][20];
printf("Transpose:\n");
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
b[j][i]=matrix[i][j];
}
}
if(rows==1||cols==1||rows!=cols)
{
for(i=0;i<cols;i++)
{
701 :oN egaP
printf("%d ",b[i][j]);
}
printf("\n");
}
}else{
for(i=0;i<rows;i++)

2 Q 4 5 A 1 9 B 4 2 : DI
{
for(j=0;j<cols;j++)
{
printf("%d ",b[i]
[j]);
}
printf("\n");
}
}
}

D- B S C & DI A- 8 2 0 2- 4 2 0 2
int main() {
printf("rows: ");
scanf("%d", &rows);
printf("columns: ");

)suomonotuA( egelloC gnireenignE RKRS


scanf("%d", &cols);
int matrix[rows][cols];

// Input: Read the matrix elements


readMatrix(matrix);

// Print the original matrix


printMatrix(matrix);

// Print the transpose of the matrix


transposeMatrix(matrix);

return 0;
}

Execution Results - All test cases have succeeded!


Test Case - 1

801 :oN egaP


User Output

rows:
2
columns:

2 Q 4 5 A 1 9 B 4 2 : DI
2
Elements:
89
65
Matrix:
8 9
6 5
Transpose:
8 6

D- B S C & DI A- 8 2 0 2- 4 2 0 2
9 5

Test Case - 2

User Output

rows:
1

)suomonotuA( egelloC gnireenignE RKRS


columns:
2
Elements:
69
Matrix:
6 9
Transpose:
6
9
Exp. Name: Demonstrate numerical
Date: 2024-12-

901 :oN egaP


S.No: 46 integration of differential equations using
03
Euler’s method

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C function to demonstrate the numerical integration of differential equations
using Euler’s method.

Your program should prompt the user to input the initial value of y (yo)the initial value of t
(to) the step size (h).and the end value fort. Implement the Euler's method in a function,
and print the values oft andy at each step.

The formula for Euler's Method:

ynext= y + h * f(y ,t)


wheref(y, t) is the derivative function representing dy/dtin the given Ordinary differential

D- B S C & DI A- 8 2 0 2- 4 2 0 2
equation.

Note: print the values of t and y up to 2 decimal places.

Source Code:

euler.c

)suomonotuA( egelloC gnireenignE RKRS


/*

011 :oN egaP


#include <stdio.h>

//write your code...

// Define the differential equation function f(y, t)


double f(double y, double t) {

2 Q 4 5 A 1 9 B 4 2 : DI
// Example: dy/dt = t*y
}
// Euler's method for numerical integration
void eulerIntegration( ) {
}

int main() {

D- B S C & DI A- 8 2 0 2- 4 2 0 2
*/
#include<stdio.h>
int main()
{
float y0,t0,h,t,x0;
printf("initial value of y (y0): ");
scanf("%f",&y0);
printf("initial value of t (t0): ");
scanf("%f",&t0);

)suomonotuA( egelloC gnireenignE RKRS


printf("step size (h): ");
scanf("%f",&h);
printf("end value for t: ");
scanf("%f",&t);
x0=t0;
while(t0<t)
{
printf("t = %.2f y = %.2f\n",t0,y0);
t0+=h;
y0=y0+h*(x0*y0);
x0=x0+h;
}
}

Execution Results - All test cases have succeeded!

Test Case - 1
User Output

111 :oN egaP


initial value of y (y0):
1
initial value of t (t0):
1
step size (h):

2 Q 4 5 A 1 9 B 4 2 : DI
3
end value for t:
10
t = 1.00 y = 1.00
t = 4.00 y = 4.00
t = 7.00 y = 52.00

Test Case - 2

D- B S C & DI A- 8 2 0 2- 4 2 0 2
User Output

initial value of y (y0):


1
initial value of t (t0):
1
step size (h):
3

)suomonotuA( egelloC gnireenignE RKRS


end value for t:
3
t = 1.00 y = 1.00
Exp. Name: Fibonacci series up to the Date: 2024-11-
S.No: 47

211 :oN egaP


given number of terms using Recursion 26

Aim:
Write a program to display the fibonacci series up to the given number of terms using
recursion process.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

fibonacciSeries.c

#include <stdio.h>
#include "fibonacciSeriesa.c"
void main() {
int n, i;
printf("n: ");
scanf("%d", &n);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("%d terms: ", n);
for (i = 0; i < n; i++) {
printf("%d ", fib(i));
}
}

fibonacciSeriesa.c

)suomonotuA( egelloC gnireenignE RKRS


// Complete the function fib()....
int fib(int n){
if(n==0)
return 0;
else if(n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

n:
4
311 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 2

10 terms: 0 1 1 2 3 5 8 13 21 34
4 terms: 0 1 1 2

User Output

10
n:
Exp. Name: LCM of two numbers using Date: 2024-11-
S.No: 48

411 :oN egaP


recursion 29

Aim:
Write a program to find the lcm (Least Common Multiple) of a given two numbers using

2 Q 4 5 A 1 9 B 4 2 : DI
recursion process.

The least common multiple ( lcm ) of two or more integers, is the smallest positive
integer that is divisible by both a and b.

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

Enter two integer values :

For example, if the user gives the input as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter two integer values : 25 15

then the program should print the result as:

The lcm of two numbers 25 and 15 = 75

Note: Write the function lcm() and recursive function gcd() in Program907a.c .
Source Code:

)suomonotuA( egelloC gnireenignE RKRS


Program907.c

#include <stdio.h>
#include "Program907a.c"
void main() {
int a, b;
printf("Enter two integer values : ");
scanf("%d %d", &a, &b);
printf("The lcm of two numbers %d and %d = %d\n", a, b,
lcm(a, b));
}

Program907a.c
int lcm(int a,int b)

511 :oN egaP


{
static int common=1;
if(common%a==0 && common%b==0)
{
return common;
}

2 Q 4 5 A 1 9 B 4 2 : DI
common++;
return lcm(a,b);
}

Execution Results - All test cases have succeeded!

Test Case - 1

D- B S C & DI A- 8 2 0 2- 4 2 0 2
User Output

Enter two integer values :


34 24
The lcm of two numbers 34 and 24 = 408

Test Case - 2

)suomonotuA( egelloC gnireenignE RKRS


User Output

Enter two integer values :


69
The lcm of two numbers 6 and 9 = 18

Test Case - 3

User Output

Enter two integer values :


345 467
The lcm of two numbers 345 and 467 = 161115

Test Case - 4

User Output

Enter two integer values :


611 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
The lcm of two numbers 123 and 420 = 17220
Test Case - 5

Enter two integer values :


User Output

123 420
Exp. Name: Write a C program to find the
Date: 2024-11-

711 :oN egaP


S.No: 49 Factorial of a given number using
26
Recursion

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a program to find the factorial of a given number using recursion process.

Note: Write the recursive function factorial() in Program901a.c .


Source Code:

Program901.c

#include <stdio.h>
#include "Program901a.c"
void main() {
long int n;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Enter an integer : ");
scanf("%ld", &n);
printf("Factorial of %ld is : %ld\n", n ,factorial(n));
}

Program901a.c

)suomonotuA( egelloC gnireenignE RKRS


long factorial(n)
{
if (n == 0 || n == 1)
{
return 1;
}
else{
return n* factorial(n-1);
}
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter an integer :
5
Factorial of 5 is : 120

811 :oN egaP


Test Case - 2

User Output

Enter an integer :

2 Q 4 5 A 1 9 B 4 2 : DI
4
Factorial of 4 is : 24

Test Case - 3

User Output

Enter an integer :
8

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Factorial of 8 is : 40320

Test Case - 4

User Output

Enter an integer :
0

)suomonotuA( egelloC gnireenignE RKRS


Factorial of 0 is : 1
Exp. Name: Ackermann function using Date: 2024-12-
S.No: 50

911 :oN egaP


Recursion 02

Aim:
Write a program to implement Ackermann function using recursion process.

2 Q 4 5 A 1 9 B 4 2 : DI
At the time of execution, the program should print the message on the console as:

Enter two numbers :

For example, if the user gives the input as:

Enter two numbers : 2 1

then the program should print the result as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
A(2, 1) = 5

Source Code:

AckermannFunction.c

#include <stdio.h>
#include "AckermannFunction1.c"

)suomonotuA( egelloC gnireenignE RKRS


void main() {
long long int m, n;
printf("Enter two numbers : ");
scanf("%lli %lli", &m, &n);
printf("A(%lli, %lli) = %lli\n", m, n, ackermannFun(m,
n));
}

AckermannFunction1.c
long long int ackermannFun(long long int m,long long int n)

021 :oN egaP


{
if(m==0)
return n+1;
else if(m>0 && n==0)
return ackermannFun(m-1,1);
else if(m>0 && n>0)

2 Q 4 5 A 1 9 B 4 2 : DI
return ackermannFun(m-1,ackermannFun(m,n-1));
return -1;
}

Execution Results - All test cases have succeeded!

Test Case - 1

D- B S C & DI A- 8 2 0 2- 4 2 0 2
User Output

Enter two numbers :


01
A(0, 1) = 2

Test Case - 2

)suomonotuA( egelloC gnireenignE RKRS


User Output

Enter two numbers :


22
A(2, 2) = 7

Test Case - 3

User Output

Enter two numbers :


21
A(2, 1) = 5

Test Case - 4

User Output

Enter two numbers :


Test Case - 5

121 :oN egaP


User Output

Enter two numbers :


10
A(1, 0) = 2

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 6

User Output

Enter two numbers :


23
A(2, 3) = 9

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Date: 2024-11-
S.No: 51 Exp. Name: Problem solving

221 :oN egaP


26

Aim:
Write a program to find the sum of n natural numbers using recursion process.

2 Q 4 5 A 1 9 B 4 2 : DI
At the time of execution, the program should print the message on the console as:

Enter value of n :

For example, if the user gives the input as:

Enter value of n : 6

then the program should print the result as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Sum of 6 natural numbers = 21

Note: Write the recursive function sum() in Program903a.c .


Source Code:

Program903.c

#include <stdio.h>
#include "Program903a.c"

)suomonotuA( egelloC gnireenignE RKRS


void main() {
int n;
printf("Enter value of n : ");
scanf("%d", &n);
printf("Sum of %d natural numbers = %d\n", n, sum(n));
}

Program903a.c

int sum(int n)
{
if(n==0)
{
return 0;
}
int result = n+sum(n-1);
return result;
}
Execution Results - All test cases have succeeded!

321 :oN egaP


Test Case - 1

User Output

Enter value of n :
5

2 Q 4 5 A 1 9 B 4 2 : DI
Sum of 5 natural numbers = 15

Test Case - 2

User Output

Enter value of n :
9
Sum of 9 natural numbers = 45

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Write a C program to Swap
Date: 2024-11-

421 :oN egaP


S.No: 52 two values by using Call-by-Address
28
method

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a program to swap two values by using call by address method.

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

Enter two integer values :

For example, if the user gives the input as:

Enter two integer values : 12 13

then the program should print the result as:

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Before swapping in main : a = 12 b = 13
After swapping in swap : *p = 13 *q = 12
After swapping in main : a = 13 b = 12

Note: Write the function swap() in Program1002a.c and do use the printf() function
with a newline character ( \n ).
Source Code:

)suomonotuA( egelloC gnireenignE RKRS


Program1002.c

#include <stdio.h>
#include "Program1002a.c"
void main() {
int a, b;
printf("Enter two integer values : ");
scanf("%d %d", &a, &b);
printf("Before swapping in main : a = %d b = %d\n", a,
b);
swap(&a, &b);
printf("After swapping in main : a = %d b = %d\n", a, b);
}

Program1002a.c
void swap(int*p,int*q)

521 :oN egaP


{
int t;
t=*p;
*p=*q;
*q=t;
printf("After swapping in swap : *p = %d *q =

2 Q 4 5 A 1 9 B 4 2 : DI
%d\n",*p,*q);
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Enter two integer values :
121 131
Before swapping in main : a = 121 b = 131
After swapping in swap : *p = 131 *q = 121
After swapping in main : a = 131 b = 121

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 2

User Output

Enter two integer values :


555 999
Before swapping in main : a = 555 b = 999
After swapping in swap : *p = 999 *q = 555
After swapping in main : a = 999 b = 555

Test Case - 3

User Output

Enter two integer values :


1001 101
Before swapping in main : a = 1001 b = 101
After swapping in swap : *p = 101 *q = 1001
After swapping in main : a = 101 b = 1001
Test Case - 4

621 :oN egaP


User Output

Enter two integer values :


9999 2999
Before swapping in main : a = 9999 b = 2999

2 Q 4 5 A 1 9 B 4 2 : DI
After swapping in swap : *p = 2999 *q = 9999
After swapping in main : a = 2999 b = 9999

Test Case - 5

User Output

Enter two integer values :


10101 11010
Before swapping in main : a = 10101 b = 11010

D- B S C & DI A- 8 2 0 2- 4 2 0 2
After swapping in swap : *p = 11010 *q = 10101
After swapping in main : a = 11010 b = 10101

)suomonotuA( egelloC gnireenignE RKRS


Date: 2024-11-
S.No: 53 Exp. Name: Dangling Pointers

721 :oN egaP


28

Aim:
Demonstrate Dangling pointer problem using a C program.

2 Q 4 5 A 1 9 B 4 2 : DI
Note: The dangling pointers are set to NULL at the end of the program to avoid undefined
behavior on the code.
Source Code:

danglingPointer.c

#include <stdio.h>
#include <stdlib.h>

int main() {

D- B S C & DI A- 8 2 0 2- 4 2 0 2
int *ptr1 = NULL;
int *ptr2 = NULL;
int value;
ptr1=(int*)malloc(sizeof(int));
printf("Enter an integer value: ");
scanf("%d",&value);
*ptr1=value;
ptr2=ptr1;
if(ptr1!=NULL)

)suomonotuA( egelloC gnireenignE RKRS


{
printf("Value through ptr2: %d\n",*ptr2);
}
else{
printf("ptr2 is a dangling pointer (invalid)\n");
}
ptr1 = NULL;
ptr2 = NULL;
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter an integer value:


54
821 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
Test Case - 2

Enter an integer value:


Value through ptr2: 54

Value through ptr2: 10


User Output

10
Exp. Name: Write a C program to Copy Date: 2024-11-
S.No: 54

921 :oN egaP


one String into another using Pointers 28

Aim:
Write a C program to copy one string into another using pointers.

2 Q 4 5 A 1 9 B 4 2 : DI
Sample Input and Output:
Enter source string : Robotic Tool
Target string : Robotic Tool
Source Code:

CopyStringPointers.c

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

D- B S C & DI A- 8 2 0 2- 4 2 0 2
char source[100], target[100];
printf("Enter source string : ");
fgets(source, sizeof(source), stdin);
copyString(target, source);
printf("Target string : %s\n", target);
}

CopyStringPointers1.c

)suomonotuA( egelloC gnireenignE RKRS


void copyString(char *target,char *source)
{
while(*source)
{
*target=*source;
source++;
target++;
}
*target = '\0';
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter source string :


CodeTantra
Target string : CodeTantra

031 :oN egaP


Test Case - 2

User Output

2 Q 4 5 A 1 9 B 4 2 : DI
Enter source string :
Robotic Tool
Target string : Robotic Tool

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Write a C program to Count
Date: 2024-11-

131 :oN egaP


S.No: 55 number of Lowercase, Uppercase, digits
28
and Other Characters using Pointers

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to find number of lowercase , uppercase , digits and
other characters using pointers.

Sample Input and Output:

Enter a string : Indo Pak 125 143 *.$


Number of uppercase letters = 2
Number of lowercase letters = 5
Number of digits = 6
Number of other characters = 7

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Source Code:

CountCharDigitOthers.c

#include <stdio.h>
#include "CountCharDigitOthers1.c"
void main() {
char str[80];

)suomonotuA( egelloC gnireenignE RKRS


int upperCount = 0, lowerCount = 0, digitCount = 0,
otherCount = 0;
printf("Enter a string : ");
gets(str);
countCharDigitOthers(str, &upperCount, &lowerCount,
&digitCount, &otherCount);
printf("Number of uppercase letters = %d\n", upperCount);
printf("Number of lowercase letters = %d\n", lowerCount);
printf("Number of digits = %d\n", digitCount);
printf("Number of other characters = %d\n", otherCount);
}

CountCharDigitOthers1.c
#include<stdio.h>

231 :oN egaP


void countCharDigitOthers
(char *str,int *upperCount,int *lowerCount,int *digitCount,int
*otherCount)
{
while(*str)
{

2 Q 4 5 A 1 9 B 4 2 : DI
if(isupper(*str))
*upperCount=*upperCount+1;
else if(islower(*str))
*lowerCount=*lowerCount+1;
else if (isdigit(*str))

*digitCount=*digitCount+1;
else

*otherCount=*otherCount+1;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
str++;
}
}

Execution Results - All test cases have succeeded!

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 1

User Output

Enter a string :
CodeTantra123&*@987.
Number of uppercase letters = 2
Number of lowercase letters = 8
Number of digits = 6
Number of other characters = 4

Test Case - 2

User Output

Enter a string :
Indo Pak 125 143 *.$
Number of uppercase letters = 2
Number of lowercase letters = 5
Number of digits = 6
Test Case - 3

331 :oN egaP


User Output

Enter a string :
12345
Number of uppercase letters = 0

2 Q 4 5 A 1 9 B 4 2 : DI
Number of lowercase letters = 0
Number of digits = 5
Number of other characters = 0

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Date: 2024-12-
S.No: 56 Exp. Name: Write the code

431 :oN egaP


06

Aim:
Write a program to read a text content from a file and display on the monitor with the help
of C program.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

readFilePrint.c

#include <stdio.h>
void main()
{
char filename[20],c;
FILE*fp=NULL;
printf("Enter the name of the file to read: ");

D- B S C & DI A- 8 2 0 2- 4 2 0 2
scanf("%s",filename);
printf("Content of the file %s:\n",filename);
fp=fopen(filename,"r");
if(fp==NULL)
return;
do{
c=fgetc(fp);
if(feof(fp))
break;

)suomonotuA( egelloC gnireenignE RKRS


printf("%c",c);
}
while(1);
printf("\n");
fclose(fp);
}
//write your code here..

file1.txt

A man was very upset with his old parents. He sometimes beat them
in anger.
One day he threw them out of his house.
They both left the house sadly and never came back.
Now, the man lived happily with his wife and children.
Twenty years later, now his children had grown up, and all of
them had gotten married.
They were doing the same with the man as he used to with his old
parents.
file2.txt

531 :oN egaP


There were two very close friends. One friend was rich and the
other was poor.
The rich friend would often ask the other to tell him whenever he
needed money so that he could help him.
But, the poor friend never got such a chance.
One day the poor friend really needed money, and he thought that

2 Q 4 5 A 1 9 B 4 2 : DI
he would ask his friend.

file3.txt

A couple was living their life happily. The womans husband had a
clothing business.
One day suddenly his health deteriorated very much and he died.
Now calamity had arisen in front of the woman.
She was very depressed about how she would take care of herself

D- B S C & DI A- 8 2 0 2- 4 2 0 2
and her children.
Her husbands shop was closed. She had no idea what to do.

Execution Results - All test cases have succeeded!

Test Case - 1

)suomonotuA( egelloC gnireenignE RKRS


User Output

Enter the name of the file to read:


file1.txt
Content of the file file1.txt:
A man was very upset with his old parents. He sometimes beat
them in anger.
One day he threw them out of his house.
They both left the house sadly and never came back.
Now, the man lived happily with his wife and children.
Twenty years later, now his children had grown up, and all of
them had gotten married.
They were doing the same with the man as he used to with his
old parents.

Test Case - 2

User Output
file2.txt
Content of the file file2.txt:

631 :oN egaP


There were two very close friends. One friend was rich and the
other was poor.
The rich friend would often ask the other to tell him whenever
he needed money so that he could help him.
But, the poor friend never got such a chance.

2 Q 4 5 A 1 9 B 4 2 : DI
One day the poor friend really needed money, and he thought
that he would ask his friend.

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: C program to write and read
Date: 2024-12-

731 :oN egaP


S.No: 57 text into a binary file using fread() and
06
fwrite()

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a C program to write and read text into a binary file using fread() and fwrite().

The program is to write a structure containing student roll number, name, marks into a file
and read them to print on the standard output device.
Source Code:

FilesStructureDemo1.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
#include<stdio.h>

831 :oN egaP


struct student {
int roll;
char name[25];
float marks;
};
void main() {

2 Q 4 5 A 1 9 B 4 2 : DI
FILE *fp;
char ch;
struct student s;
fp = fopen("student-information.txt", "wb"); // Complete
the statement
do {
printf("Roll no: ");
scanf("%d",&s.roll); // Complete the statement
printf("Name: ");
scanf("%s",&s.name); // Complete the statement

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Marks: ");
scanf("%f",&s.marks); // Complete the statement
fwrite(&s,sizeof(s),1,fp); // Complete the
statement
printf("Want to add another data (y/n): ");
scanf(" %c", &ch);
}while (ch=='y'||ch=='Y'); // Complete the condition
printf("Data written successfully\n");
fclose(fp);

)suomonotuA( egelloC gnireenignE RKRS


fp = fopen("student-information.txt", "rb"); // Complete the
statement
printf("Roll\tName\tMarks\n");
while (fread(&s,sizeof(s),1,fp) > 0) { // Complete the
condition
printf("%d\t%s\t%f\n", s.roll,s.name,s.marks); //
complete the statement
}
fclose(fp);
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Roll no:
501
Name:

931 :oN egaP


Ganga
Marks:
92
Want to add another data (y/n):

2 Q 4 5 A 1 9 B 4 2 : DI
y
Roll no:
502
Name:
Smith
Marks:
65
Want to add another data (y/n):
n

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Data written successfully
Roll Name Marks
501 Ganga 92.000000
502 Smith 65.000000

)suomonotuA( egelloC gnireenignE RKRS


Exp. Name: Copy contents of one file into Date: 2024-12-
S.No: 58

041 :oN egaP


another file. 06

Aim:
Write a C program that creates a file (eg: SampleTextFile1.txt) and allows a user to input
text until they enter '@' into the file. The program then creates another file (eg:

2 Q 4 5 A 1 9 B 4 2 : DI
SampleTextFile2.txt) and copies the contents of the first file to the second file. Finally, it
should display the contents of the second file.

Input Format:
The program prompts the user to enter text, which can include any characters. The input
ends when the user types the character @.

Output Format:
The program outputs the copied text from the second file in the following format: "Copied
text is : [text]" where [text] is the content copied from the first text file.

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Source Code:

copy.c

)suomonotuA( egelloC gnireenignE RKRS


#include <stdio.h>

141 :oN egaP


void main() {
FILE *fp, *fp1, *fp2;
char ch;

fp = fopen("one.text","w" ); // write the missing

2 Q 4 5 A 1 9 B 4 2 : DI
code

printf("Enter the text with @ at end : ");


while ((ch = getchar()) != '@') {
putc(ch, fp);
}
putc(ch, fp);
fclose(fp);
fp1=fopen("one.text","r");
fp2=fopen("two text","w");

D- B S C & DI A- 8 2 0 2- 4 2 0 2
printf("Copied text is : ");
while(!feof(fp1)){
fscanf(fp1,"%c",&ch);
if(
feof(fp1)||ch=='@')
break;
fprintf(fp2,"%c",ch);
printf("%c",ch);
}

)suomonotuA( egelloC gnireenignE RKRS


printf("\n");
fclose(fp1);
fclose(fp2);
// write the missing code...

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter the text with @ at end :


CodeTantra received
best Startup award from Hysea in
2016@
241 :oN egaP 2 Q 4 5 A 1 9 B 4 2 : DI D- B S C & DI A- 8 2 0 2- 4 2 0 2 )suomonotuA( egelloC gnireenignE RKRS
best Startup award from Hysea in 2016
Exp. Name: Merge two files and store
Date: 2024-12-

341 :oN egaP


S.No: 59 their contents in another file using
06
command-line arguments

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a program to merge two files and stores their contents in another file using
command-line arguments.
• Open a new file specified in argv[1] in write mode
• Write the content onto the file
• Close the file
• Open another new file specified in argv[2] in write mode
• Write the content onto the file
• Close the file
• Open first existing file specified in argv[1] in read mode
• Open a new file specified in argv[3] in write mode
• Copy the content from first existing file to new file

D- B S C & DI A- 8 2 0 2- 4 2 0 2
• Close the first existing file
• Open another existing file specified in argv[2] in read mode
• Copy its content from existing file to new file
• Close that existing file
• Close the merged file
Source Code:

MergeFilesArgs.c

)suomonotuA( egelloC gnireenignE RKRS


#include <stdio.h>

441 :oN egaP


void main(int argc,char*argv[]) {// fill argument parameters
FILE *fp1, *fp2, *fp3;
char ch;
fp1 = fopen(argv[1] , "w"); // Open file in corresponding
mode
printf("Enter the text with @ at end for file-1 :\n");

2 Q 4 5 A 1 9 B 4 2 : DI
while ((ch=getchar())!='@') { // Write the condition
putc(ch, fp1);
}
putc(ch, fp1);
fclose(fp1);
fp2 = fopen( argv[2], "w"); // Open file in corresponding
mode
printf("Enter the text with @ at end for file-2 :\n");
while ((ch=getchar())!='@') { // Write the condition
putc(ch, fp2);

D- B S C & DI A- 8 2 0 2- 4 2 0 2
}
putc(ch, fp2);
fclose(fp2);
fp1 = fopen(argv[1] , "r"); // Open a first existed file
in read mode
fp3 = fopen(argv[3] , "w"); // Open a new file in write
mode
while ((ch=fgetc(fp1))!='@') { // Repeat loop till get @
at the end of existed file

)suomonotuA( egelloC gnireenignE RKRS


putc(ch, fp3);
}
fclose(fp1); // Close the first existed file
fp2 = fopen(argv[2] , "r "); // Open a secong existed
file in read mode
while ((ch=fgetc(fp2))!='@') { // Repeat loop till get @
at the end of existed file
putc(ch, fp3);
}
putc(ch, fp3);
fclose(fp2);
fclose(fp3);
fp3 = fopen(argv[3] , "r"); // Open the merged file in
read mode
printf("Merged text is : ");
while ((ch=fgetc(fp3))!='@') { // Repeat loop till get @
at the end of merged file
putchar(ch);
}
printf("\n");
fclose(fp3); // Close the merged file

541 :oN egaP


}

Execution Results - All test cases have succeeded!

2 Q 4 5 A 1 9 B 4 2 : DI
Test Case - 1

User Output

Enter the text with @ at end for file-1 :


This is CodeTantra
They implemented automatic
robotic tool@
Enter the text with @ at end for file-2 :
Started the company in

D- B S C & DI A- 8 2 0 2- 4 2 0 2
2014@
Merged text is : This is CodeTantra
They implemented automatic robotic tool
Started the company in
2014

)suomonotuA( egelloC gnireenignE RKRS


Test Case - 2

User Output

Enter the text with @ at end for file-1 :


Best
Fair
Awesome@
Enter the text with @ at end for file-2 :
False@
Merged text is : Best
Fair
Awesome
False
Exp. Name: Write a C program to Count
Date: 2024-12-

641 :oN egaP


S.No: 60 number of Characters, Words and Lines
06
of a given File

Aim:

2 Q 4 5 A 1 9 B 4 2 : DI
Write a program to count number of characters, words and lines of given text file.
• open a new file " DemoTextFile2.txt " in write mode
• write the content onto the file
• close the file
• open the same file in read mode
• read the text from file and find the characters, words and lines count
• print the counts of characters, words and lines
• close the file
Source Code:

Program1508.c

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
#include <stdio.h>

741 :oN egaP


void main() {
FILE *fp;
char ch;
int charCount = 0, wordCount = 0, lineCount = 0;
fp = fopen("DemoTextFile2.txt", "w"); // Open a new file
in write mode

2 Q 4 5 A 1 9 B 4 2 : DI
printf("Enter the text with @ at end : ");
while ((ch=getchar())!='@') { // Repeat loop till read @
at the end
putc(ch,fp); // Put read character onto the file
}
putc(ch,fp); // Put delimiter @ at the end on the file
fclose(fp); // Close the file
fp = fopen("DemoTextFile2.txt", "r"); // Open the
existing file in read mode
do {

D- B S C & DI A- 8 2 0 2- 4 2 0 2
if (ch==' '||ch=='\t'||ch=='\n'||ch=='\0') //
Write the condition to count words
wordCount++;
else
charCount++;
if (ch=='\n'||ch=='\0') // Write the condition to
count lines
lineCount++;
} while ((ch=fgetc(fp))!='@'); // Repeat loop till read @

)suomonotuA( egelloC gnireenignE RKRS


at the end
fclose(fp);
printf("Total characters : %d\n", charCount-1);
printf("Total words : %d\n", wordCount+1);
printf("Total lines : %d\n", lineCount+1);
}

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

Enter the text with @ at end :


Arise! Awake!
and stop not until
the goal is reached@
Total words : 10
Total lines : 3

841 :oN egaP


Test Case - 2

User Output

2 Q 4 5 A 1 9 B 4 2 : DI
Enter the text with @ at end :
Believe in your self
and the world will be
at your feet@
Total characters : 44
Total words : 12
Total lines : 3

D- B S C & DI A- 8 2 0 2- 4 2 0 2
)suomonotuA( egelloC gnireenignE RKRS
Exp. Name: Print the last n characters of Date: 2024-12-
S.No: 61

941 :oN egaP


a file by reading the file 09

Aim:
Write a C program to print the last n characters of a file by reading the file name and n
value from the command line.

2 Q 4 5 A 1 9 B 4 2 : DI
Source Code:

file.c

#include<stdio.h>
#include<stdlib.h>
void main(int argc,char *argv[]){
FILE *fp;
char ch;
int n;

D- B S C & DI A- 8 2 0 2- 4 2 0 2
long len;
fp = fopen(argv[1] , "r");
n=atoi(argv[2]);
fseek(fp,0,SEEK_END);
len = ftell(fp);
fseek(fp,(len-n),SEEK_SET);
while((ch=fgetc(fp))){
if(feof(fp)) break;
putchar(ch);

)suomonotuA( egelloC gnireenignE RKRS


}
printf("\n");
fclose(fp);
}

input1.txt

Although practicality beats purity.


Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
Now is better than never.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.

input2.txt
Beautiful is better than ugly.

051 :oN egaP


Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.

2 Q 4 5 A 1 9 B 4 2 : DI
Everything matters.

test1.txt

CodeTantra
Start coding in 60 mins

test2.txt

D- B S C & DI A- 8 2 0 2- 4 2 0 2
Hydrofoil is an underwater fin with a falt or curved wing-like
surface that is designed to lift a moving boat or ship
by means of the reaction upon its surface

test3.txt

Count the sentences in the file.

)suomonotuA( egelloC gnireenignE RKRS


Count the words in the file.
Count the characters in the file.

Execution Results - All test cases have succeeded!

Test Case - 1

User Output

good idea.

Test Case - 2

User Output

verything matters.

You might also like