Programming

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 40

KPIT C PROGRAMS

Total question done: 67

A)Getting Started:

1)Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to
convert this temperature into Centigrade degrees.

Code:

#include <stdio.h>

int main() {
float fahrenheit, celsius;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
celsius = (fahrenheit - 32) * 5 / 9;
printf("Temperature in Celsius: %.2f\n", celsius);
return 0;
}

2)The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a
program to calculate the area and perimeter of the rectangle, and the area and circumference of the
circle.

Code:
#include <stdio.h>

#define PI 3.14159

int main() {
float length, breadth, radius;
float area_rectangle, perimeter_rectangle, area_circle, circumference_circle;

printf("Enter the length and breadth of the rectangle: ");


scanf("%f %f", &length, &breadth);

printf("Enter the radius of the circle: ");


scanf("%f", &radius);

area_rectangle = length * breadth;


perimeter_rectangle = 2 * (length + breadth);

area_circle = PI * radius * radius;


circumference_circle = 2 * PI * radius;

printf("Area of the rectangle: %.2f\n", area_rectangle);


printf("Perimeter of the rectangle: %.2f\n", perimeter_rectangle);
printf("Area of the circle: %.2f\n", area_circle);
printf("Circumference of the circle: %.2f\n", circumference_circle);
return 0;
}

3)Paper of size A0 has dimensions 1189 mm x 841 mm. Each subsequent size A(n) is defined as A(n-1)
cut in half, parallel to its shorter sides. Thus, paper of size A1 would have dimensions 841 mm x 594
mm. Write a program to calculate and print paper sizes
A0, A1, A2, … A8.

Code:
#include <stdio.h>

int main() {
int width = 1189, height = 841;
int temp;

for (int i = 0; i <= 8; i++) {


printf("A%d: %d mm x %d mm\n", i, width, height);
temp = width;
width = height;
height = temp / 2;
}

return 0;
}

B)C instruction:

Code:#include <stdio.h>

int main() {
int num, sum = 0, digit;

printf("Enter a five-digit number: ");


scanf("%d", &num);

digit = num % 10;


sum += digit;
num /= 10;

digit = num % 10;


sum += digit;
num /= 10;

digit = num % 10;


sum += digit;
num /= 10;

digit = num % 10;


sum += digit;
num /= 10;

digit = num % 10;


sum += digit;
printf("Sum of the digits: %d\n", sum);

return 0;
}

Code:

#include <stdio.h>

int main() {
int n, fact = 1;
printf("Enter a number: ");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
fact *= i;
}
printf("Factorial of %d is %d\n", n, fact);
return 0;
}

Code:
#include <stdio.h>
#include <math.h>

#define EARTH_RADIUS 3963.0

int main() {
double lat1, lon1, lat2, lon2, radians1, radians2, distance;

printf("Enter latitudes (L1, L2) in degrees: ");


scanf("%lf %lf", &lat1, &lat2);

printf("Enter longitudes (G1, G2) in degrees: ");


scanf("%lf %lf", &lon1, &lon2);
radians1 = lat1 * M_PI / 180.0;
radians2 = lat2 * M_PI / 180.0;

distance = EARTH_RADIUS * acos(sin(radians1) * sin(radians2) +


cos(radians1) * cos(radians2) * cos((lon1 - lon2) * M_PI / 180.0));

printf("Distance between two places: %.2f nautical miles\n", distance);

return 0;
}

Code:
#include <stdio.h>
#include <math.h>

int main() {
double temperature, wind_speed, wind_chill;

printf("Enter temperature (in degrees Celsius): ");


scanf("%lf", &temperature);

printf("Enter wind speed (in m/s): ");


scanf("%lf", &wind_speed);

wind_chill = 35.74 + 0.6215 * temperature + (0.4275 * temperature - 35.75) * pow(wind_speed,


0.16);

printf("Wind chill factor: %.2f degrees Celsius\n", wind_chill);

return 0;
}

Code:
#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979323846

int main() {
double angle, radians;

printf("Enter angle in degrees: ");


scanf("%lf", &angle);

// Convert from degrees to radians


radians = angle * PI / 180.0;

double sine = sin(radians);


double cosine = cos(radians);
double tangent = tan(radians);
double cosecant = 1 / sine;
double secant = 1 / cosine;
double cotangent = 1 / tangent;

printf("Sine: %.4f\n", sine);


printf("Cosine: %.4f\n", cosine);
printf("Tangent: %.4f\n", tangent);
printf("Cosecant: %.4f\n", cosecant);
printf("Secant: %.4f\n", secant);
printf("Cotangent: %.4f\n", cotangent);

return 0;
}

Code:
#include <stdio.h>

int main() {
int c, d, temp;

printf("Enter the value of C: ");


scanf("%d", &c);

printf("Enter the value of D: ");


scanf("%d", &d);
temp = c;
c = d;
d = temp;

printf("After swapping:\n");
printf("C = %d\n", c);
printf("D = %d\n", d);

return 0;
}

C)Decision Control Instruction:

(a) A five-digit number is entered through the keyboard. Write a program to obtain the reversed
number and to determine whether the original and reversed numbers are equal or not.

Code:
#include <stdio.h>

int main() {
int num, reversed_num = 0, remainder;

printf("Enter a five-digit number: ");


scanf("%d", &num);

while (num != 0) {
remainder = num % 10;
reversed_num = reversed_num * 10 + remainder;
num /= 10;
}

printf("Reversed Number: %d\n", reversed_num);

if (reversed_num == num) {
printf("The original and reversed numbers are equal.\n");
} else {
printf("The original and reversed numbers are not equal.\n");
}

return 0;
}

(b) If ages of Ram, Shyam and Ajay are input through the keyboard, write a program to determine the
youngest of the three.

Code:

#include <stdio.h>
int main() {
int ram_age, shyam_age, ajay_age;

printf("Enter Ram's age: ");


scanf("%d", &ram_age);

printf("Enter Shyam's age: ");


scanf("%d", &shyam_age);

printf("Enter Ajay's age: ");


scanf("%d", &ajay_age);

if (ram_age < shyam_age && ram_age < ajay_age) {


printf("Ram is the youngest.\n");
} else if (shyam_age < ram_age && shyam_age < ajay_age) {
printf("Shyam is the youngest.\n");
} else {
printf("Ajay is the youngest.\n");
}

return 0;
}

(c) Write a program to check whether a triangle is valid or not, if three angles of the triangle are
entered through the keyboard. A triangle is valid if the sum of all the three angles is equal to 180
degrees.

Code:

#include <stdio.h>

int main() {
int angle1, angle2, angle3;

printf("Enter the first angle: ");


scanf("%d", &angle1);

printf("Enter the second angle: ");


scanf("%d", &angle2);

printf("Enter the third angle: ");


scanf("%d", &angle3);

if (angle1 + angle2 + angle3 == 180) {


printf("The triangle is valid.\n");
} else {
printf("The triangle is not valid.\n");
}

return 0;
}

(d) Write a program to find the absolute value of a number entered through the keyboard.

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

int main() {
int num;

printf("Enter a number: ");


scanf("%d", &num);

printf("The absolute value of %d is %d.\n", num, abs(num));

return 0;
}

(e) Given the length and breadth of a rectangle, write a program to find whether the area of the
rectangle is greater than its perimeter. For example, the area of the rectangle with length = 5 and
breadth = 4 is greater than its perimeter.

Code:
#include <stdio.h>

int main() {
int length, breadth, area, perimeter;

printf("Enter the length of the rectangle: ");


scanf("%d", &length);

printf("Enter the breadth of the rectangle: ");


scanf("%d", &breadth);

area = length * breadth;


perimeter = 2 * (length + breadth);

if (area > perimeter) {


printf("The area of the rectangle is greater than its perimeter.\n");
} else {
printf("The area of the rectangle is not greater than its perimeter.\n");
}

return 0;
}

(f) Given three points (x1, y1), (x2, y2) and (x3, y3), write a program to check if the three points fall on
one straight line.

Code:
#include <stdio.h>

int main() {
float x1, y1, x2, y2, x3, y3;
float slope1, slope2;

printf("Enter the coordinates of the first point (x1, y1): ");


scanf("%f %f", &x1, &y1);

printf("Enter the coordinates of the second point (x2, y2): ");


scanf("%f %f", &x2, &y2);
printf("Enter the coordinates of the third point (x3, y3): ");
scanf("%f %f", &x3, &y3);

slope1 = (y2 - y1) / (x2 - x1);


slope2 = (y3 - y2) / (x3 - x2);

if (slope1 == slope2) {
printf("The three points fall on one straight line.\n");
} else {
printf("The three points do not fall on one straight line.\n");
}

return 0;
}

(g) Given the coordinates (x, y) of center of a circle and its radius, write a program that will determine
whether a point lies inside the circle, on the circle or outside the circle. (Hint: Use sqrt( ) and pow( )
functions)

Code:

#include <stdio.h>
#include <math.h>

int main() {
float center_x, center_y, radius, point_x, point_y, distance;

printf("Enter the coordinates of the center of the circle (x, y): ");
scanf("%f %f", &center_x, &center_y);

printf("Enter the radius of the circle: ");


scanf("%f", &radius);

printf("Enter the coordinates of the point (x, y): ");


scanf("%f %f", &point_x, &point_y);

distance = sqrt(pow(point_x - center_x, 2) + pow(point_y - center_y, 2));

if (distance < radius) {


printf("The point lies inside the circle.\n");
} else if (distance == radius) {
printf("The point lies on the circle.\n");
} else {
printf("The point lies outside the circle.\n");
}

return 0;
}

(h) Given a point (x, y), write a program to find out if it lies on X-axis, Yaxis or origin.

Code:
#include <stdio.h>

int main() {
float x, y;

printf("Enter the coordinates of the point (x, y): ");


scanf("%f %f", &x, &y);

if (x == 0 && y == 0) {
printf("The point lies at the origin.\n");
} else if (x == 0) {
printf("The point lies on the Y-axis.\n");
} else if (y == 0) {
printf("The point lies on the X-axis.\n");
} else {
printf("The point does not lie on the X-axis, Y-axis, or origin.\n");
}

return 0;
}

(i) According to Gregorian calendar, it was Monday on the date 01/01/01. If any year is input through
the keyboard write a program to find out what is the day on 1st January of this year.

Code:
#include <stdio.h>

int main() {
int year, day;

printf("Enter a year: ");


scanf("%d", &year);

// Zeller's Congruence algorithm to find the day of the week


day = (1 + 5*((year - 1) % 4) + 4*((year - 1) % 100) + 6*((year - 1) % 400)) % 7;

switch(day) {
case 0:
printf("Sunday\n");
break;
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
}

return 0;
}

4. More Complex Decision Making:

Code:

#include <stdio.h>

int main() {
int side1, side2, side3;

printf("Enter three sides of the triangle: ");


scanf("%d %d %d", &side1, &side2, &side3);

// Check for invalid triangle (sum of any two sides must be greater than the third)
if (side1 + side2 <= side3 || side2 + side3 <= side1 || side1 + side3 <= side2) {
printf("Invalid triangle (sides must form a valid triangle)\n");
return 1;
}

// Check for equilateral triangle


if (side1 == side2 && side2 == side3) {
printf("The triangle is equilateral.\n");
} else if (side1 == side2 || side2 == side3 || side1 == side3) {
printf("The triangle is isosceles.\n");
} else {
// Check for right-angled triangle (using Pythagorean theorem)
if (side1 * side1 == side2 * side2 + side3 * side3 ||
side2 * side2 == side1 * side1 + side3 * side3 ||
side3 * side3 == side1 * side1 + side2 * side2) {
printf("The triangle is right-angled.\n");
} else {
printf("The triangle is scalene.\n");
}
}

return 0;
}

Code:

#include <stdio.h>

int main() {
int red, green, blue;
float white, cyan, magenta, yellow, black;

printf("Enter RGB values (0-255): ");


scanf("%d %d %d", &red, &green, &blue);

// Normalize RGB values to range [0, 1]


red = (float) red / 255.0;
green = (float) green / 255.0;
blue = (float) blue / 255.0;

// Calculate white value


white = fmax(red, green, blue);

// Check for black color (all RGB values are 0)


if (white == 0) {
cyan = magenta = yellow = 0.0;
black = 1.0;
} else {
// Calculate CMY values
cyan = (1.0 - red) / white;
magenta = (1.0 - green) / white;
yellow = (1.0 - blue) / white;

// Calculate black value


black = 1.0 - white;
}

printf("CMYK: Cyan = %.2f, Magenta = %.2f, Yellow = %.2f, Black = %.2f\n", cyan, magenta, yellow,
black);

return 0;
}

The grades are as follows:


Grade is 10 if all three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of
hardness, carbon content and tensile strength of the steel under
consideration and output the grade of the steel.

Code:

#include <stdio.h>

int main() {
int red, green, blue;
float white, cyan, magenta, yellow, black;
printf("Enter RGB values (0-255): ");
scanf("%d %d %d", &red, &green, &blue);

// Normalize RGB values to range [0, 1]


red = (float) red / 255.0;
green = (float) green / 255.0;
blue = (float) blue / 255.0;

// Calculate white value


white = fmax(red, green, blue);

// Check for black color (all RGB values are 0)


if (white == 0) {
cyan = magenta = yellow = 0.0;
black = 1.0;
} else {
// Calculate CMY values
cyan = (1.0 - red) / white;
magenta = (1.0 - green) / white;
yellow = (1.0 - blue) / white;

// Calculate black value


black = 1.0 - white;
}

printf("CMYK: Cyan = %.2f, Magenta = %.2f, Yellow = %.2f, Black = %.2f\n", cyan, magenta, yellow,
black);

return 0;
}

Code:

#include <stdio.h>

int main() {
float hardness, carbon_content, tensile_strength;
int grade;

printf("Enter hardness of the steel: ");


scanf("%f", &hardness);

printf("Enter carbon content of the steel: ");


scanf("%f", &carbon_content);

printf("Enter tensile strength of the steel: ");


scanf("%f", &tensile_strength);

// Determine grade based on conditions


if (hardness > 50 && carbon_content < 0.7 && tensile_strength > 5600) {
grade = 10;
} else if (hardness > 50 && carbon_content < 0.7) {
grade = 9;
} else if (carbon_content < 0.7 && tensile_strength > 5600) {
grade = 8;
} else if (hardness > 50 && tensile_strength > 5600) {
grade = 7;
} else if (hardness > 50 || carbon_content < 0.7 || tensile_strength > 5600) {
grade = 6;
} else {
grade = 5;
}

printf("The grade of the steel is: %d\n", grade);

return 0;
}

5: Loop Control Instruction-

(a) Write a program to print all the ASCII values and their equivalent characters using a while loop.
The ASCII values vary from 0 to 255.

Code:
#include <stdio.h>

int main() {
int i = 0;

while (i <= 255) {


printf("ASCII value: %d, Character: %c\n", i, i);
i++;
}

return 0;
}

(b) Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of each
digit of the number is equal to the number itself, then the number is called an Armstrong number. For
example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ).

Code:

#include <stdio.h>

int main() {
int num, originalNum, remainder, result, i;

printf("Armstrong numbers between 1 and 500:\n");

for (i = 1; i <= 500; i++) {


num = i;
result = 0;

originalNum = num;

while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}

if (result == num) {
printf("%d\n", num);
}
}

return 0;
}

(c) Write a program for a matchstick game being played between the
computer and a user. Your program should ensure that the
computer always wins. Rules for the game are as follows:
_x0010_ There are 21 matchsticks.
_x0010_ The computer asks the player to pick 1, 2, 3, or 4 matchsticks.
_x0010_ After the person picks, the computer does its picking.
_x0010_ Whoever is forced to pick up the last matchstick loses the game.

Code:

#include <stdio.h>

int main() {
int matchsticks = 21, user_pick, comp_pick;

while (1) {
printf("Remaining matchsticks: %d\n", matchsticks);
printf("Pick 1, 2, 3, or 4 matchsticks: ");
scanf("%d", &user_pick);

if (user_pick < 1 || user_pick > 4) {


printf("Invalid input. Please pick 1, 2, 3, or 4 matchsticks.\n");
continue;
}

comp_pick = 5 - user_pick;
printf("Computer picks: %d\n", comp_pick);

matchsticks -= (user_pick + comp_pick);

if (matchsticks <= 0) {
printf("Computer wins!\n");
break;
}
}

return 0;
}

(d) Write a program to enter numbers till the user wants. At the end it should display the count of
positive, negative and zeros entered.

Code:
#include <stdio.h>

int main() {
int num, positive_count = 0, negative_count = 0, zero_count = 0;
char choice;

do {
printf("Enter a number: ");
scanf("%d", &num);

if (num > 0) {
positive_count++;
} else if (num < 0) {
negative_count++;
} else {
zero_count++;
}

printf("Do you want to enter another number? (y/n): ");


scanf(" %c", &choice);
} while (choice == 'y' || choice == 'Y');

printf("Positive numbers: %d\n", positive_count);


printf("Negative numbers: %d\n", negative_count);
printf("Zeros: %d\n", zero_count);

return 0;
}

(e) Write a program to receive an integer and find its octal equivalent.
(Hint: To obtain octal equivalent of an integer, divide it continuously by 8 till dividend doesn’t become
zero, then write the remainders obtained in reverse direction.)

Code:
#include <stdio.h>

int main() {
int num, octal_num = 0, remainder, place = 1;

printf("Enter an integer: ");


scanf("%d", &num);

while (num != 0) {
remainder = num % 8;
octal_num += remainder * place;
num /= 8;
place *= 10;
}

printf("Octal equivalent: %d\n", octal_num);

return 0;
}
(f) Write a program to find the range of a set of numbers entered through the keyboard. Range is the
difference between the smallest and biggest number in the list.

Code:
#include <stdio.h>

int main() {
int num, smallest, largest;

printf("Enter the first number: ");


scanf("%d", &num);
smallest = largest = num;

while (1) {
printf("Enter the next number (or 0 to finish): ");
scanf("%d", &num);

if (num == 0) {
break;
}

if (num < smallest) {


smallest = num;
}

if (num > largest) {


largest = num;
}
}

printf("Range: %d\n", largest - smallest);

return 0;
}

5.More Complex Repetition:


(a) Write a program to print the multiplication table of the number entered by the user. The table
should get displayed in the following form:
29 * 1 = 29
29 * 2 = 58

Code:
#include <stdio.h>

int main() {
int num, i;

printf("Enter a number to display its multiplication table: ");


scanf("%d", &num);

for (i = 1; i <= 10; i++) {


printf("%d * %d = %d\n", num, i, num * i);
}
return 0;
}

(b) According to a study, the approximate level of intelligence of a person can be calculated using the
following formula:
i = 2 + ( y + 0.5 x )
Write a program that will produce a table of values of i, y and x, where y varies from 1 to 6, and, for
each value of y, x varies from 5.5 to 12.5 in steps of 0.5.

Code:
#include <stdio.h>

int main() {
float x, y, i;

printf("y\tx\ti\n");
printf("--\t--\t--\n");

for (y = 1; y <= 6; y++) {


for (x = 5.5; x <= 12.5; x += 0.5) {
i = 2 + (y + 0.5 * x);
printf("%.0f\t%.1f\t%.1f\n", y, x, i);
}
printf("\n");
}

return 0;
}

(c) When interest compounds q times per year at an annual rate of r % for n years, the principal p
compounds to an amount a as per the following formula a=p(l+r/q)ng Write a program to read 10 sets
of p, r, n & q and calculate the corresponding as.

Code:

#include <stdio.h>
#include <math.h>

int main() {
float p, r, a;
int n, q, i;

printf("Enter 10 sets of p, r, n, and q:\n");

for (i = 1; i <= 10; i++) {


printf("Set %d:\n", i);

printf("Enter the principal (p): ");


scanf("%f", &p);

printf("Enter the annual interest rate (r): ");


scanf("%f", &r);

printf("Enter the number of years (n): ");


scanf("%d", &n);
printf("Enter the number of times interest compounds per year (q): ");
scanf("%d", &q);

a = p * pow(1 + r / q, n * q);

printf("The final amount (a) is: %.2f\n\n", a);


}

return 0;
}

(d) The natural logarithm can be approximated by the following series.


x-1+ If x —1 ) ( x —1 )3+ " - ) 4 + 2( x ) 21 ) 21 x ) If x is input through the keyboard, write a program to
calculate the sum of first seven terms of this series.

Code:

#include <stdio.h>
#include <math.h>

int main() {
float x, sum = 0;
int i;

printf("Enter a value for x: ");


scanf("%f", &x);

for (i = 1; i <= 7; i++) {


sum += pow(-1, i+1) * pow(x - 1, i) / i;
}

printf("Sum of the first seven terms of the series: %.4f\n", sum);

return 0;
}

(e) Write a program to generate all Pythagorean Triplets with side length less than or equal to 30.

Code:

#include <stdio.h>

int main() {
int a, b, c;

printf("Pythagorean Triplets with side length <= 30:\n");

for (a = 1; a <= 30; a++) {


for (b = a; b <= 30; b++) {
c = sqrt(a * a + b * b);
if (c <= 30 && c * c == a * a + b * b) {
printf("%d, %d, %d\n", a, b, c);
}
}
}

return 0;
}

F)Population of a town today is 100000. The population has increased steadily at the rate of 10% per
year for last 10 years. Write a program to determine the population at the end of each year in the last
decade.

Code:
#include <stdio.h>
#include <math.h>

int main() {
int initial_population = 100000;
float growth_rate = 0.10;
int num_years = 10;
float population;

printf("Year\tPopulation\n");
printf("----\t----------\n");

for (int i = 1; i <= num_years; i++) {


population = initial_population * pow(1 + growth_rate, i);
printf("%d\t%.0f\n", i, population);
}

return 0;
}

G)Ramanujan number (1729) is the smallest number that can be expressed as sum of two cubes in
two different ways-1729 can be expressed as 13 + 123 and 93 + 103. Write a program to print all such
numbers up to a reasonable limit.
Code:
#include <stdio.h>
#include <math.h>

int main() {
int limit = 1000000;
int i, j, k;

printf("Ramanujan numbers up to %d:\n", limit);

for (i = 1; i <= cbrt(limit); i++) {


for (j = i + 1; j <= cbrt(limit); j++) {
k = i * i * i + j * j * j;
if (k <= limit) {
for (int m = j + 1; m <= cbrt(k); m++) {
if (k == m * m * m) {
printf("%d = %d^3 + %d^3 = %d^3 + %d^3\n", k, i, j, j, m);
}
}
} else {
break;
}
}
}

return 0;
}
(h) Write a program to print 24 hours of day with suitable suffixes like AM, PM, Noon and Midnight.

Code:

#include <stdio.h>

int main() {
int hour;

for (hour = 0; hour < 24; hour++) {


if (hour == 0) {
printf("12:00 Midnight\n");
} else if (hour < 12) {
printf("%d:00 AM\n", hour);
} else if (hour == 12) {
printf("12:00 Noon\n");
} else {
printf("%d:00 PM\n", hour - 12);
}
}

return 0;
}

Code:
#include <stdio.h>

int main() {
int i, j = 1;

for (i = 1; i <= 4; i++) {


if (i == 1) {
printf(" %d\n", j++);
} else if (i == 2) {
printf(" %d %d\n", j++, j++);
} else if (i == 3) {
printf(" %d %d %d\n", j++, j++, j++);
} else {
printf("%d %d %d %d\n", j++, j++, j++, j++);
}
}

return 0;
}

7 Case Control Instruction:


Write a menu driven program which has following options:
1. Factorial of a number
2. Prime or not
3. Odd or even
4. Exit

Code:

# include <stdio.h>
# include <stdlib.h>
int main( )
{
int choice, num, i, fact ;
while ( 1 )
{
printf ( "\n1. Factorial\n" ) ;
printf ( "2. Prime\n" ) ;
printf ( "3. Odd / Even\n" ) ;
printf ( "4. Exit\n" ) ;
printf ( "Your choice? " ) ;
scanf ( "%d", &choice ) ;
switch ( choice )
{
case 1 :
printf ( "\nEnter number: " ) ;
scanf ( "%d", &num ) ;
fact = 1 ;
for ( i = 1 ; i <= num ; i++ )
fact = fact * i ;
printf ( "Factorial value = %d\n", fact ) ;
break ;
case 2 :
printf ( "\nEnter number: " ) ;
scanf ( "%d", &num ) ;
for ( i = 2 ; i < num ; i++ )
{
if ( num % i == 0 )
{
printf ( "Not a prime number\n" ) ;
break ;
}
if ( i == num )
printf ( "Prime number\n" ) ;
break ;
case 3 :
printf ( "\nEnter number: " ) ;
scanf ( "%d", &num ) ;
if ( num % 2 == 0 )
printf ( "Even number\n" ) ;
else
printf ( "Odd number\n" ) ;
break ;
case 4 :
exit ( 0 ) ; /* Terminates program execution */
default :
printf ( "Wrong choice!\a\n" ) ;
}
}
return 0 ;
}

8.Function:
(a)Any year is entered through the keyboard. Write a function to determine whether the year is a leap
year or not.
Code:

#include <stdio.h>

int isLeapYear(int year) {


if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return 1; // Leap year
} else {
return 0; // Not a leap year
}
}

int main() {
int year;

printf("Enter a year: ");


scanf("%d", &year);

if (isLeapYear(year)) {
printf("%d is a leap year.\n", year);
} else {
printf("%d is not a leap year.\n", year);
}

return 0;
}

(b)A positive integer is entered through the keyboard. Write a function to obtain the prime factors of
this number. For example, prime factors of 24 are 2, 2, 2 and 3, whereas prime factors of 35 are 5 and
7.
Code:

#include <stdio.h>

void primeFactors(int n) {
int i;

printf("Prime factors of %d are: ", n);

for (i = 2; i <= n; i++) {


while (n % i == 0) {
printf("%d ", i);
n /= i;
}
}

printf("\n");
}

int main() {
int num;

printf("Enter a positive integer: ");


scanf("%d", &num);

primeFactors(num);

return 0;
}

9.Pointers
(a) Given three variables x, y, z, write a function to circularly shift their values to right. In other words,
if x = 5, y = 8, z = 10, after circular shift y = 5, z = 8, x =10. Call the function with variables a, b, c to
circularly shift values.

Code:

#include <stdio.h>

void circularShift(int *x, int *y, int *z) {


int temp = *x;
*x = *z;
*z = *y;
*y = temp;
}

int main() {
int a = 5, b = 8, c = 10;

printf("Before circular shift: a = %d, b = %d, c = %d\n", a, b, c);

circularShift(&a, &b, &c);

printf("After circular shift: a = %d, b = %d, c = %d\n", a, b, c);

return 0;
}

(b) Define a function that receives weight of a commodity in Kilograms and returns the equivalent
weight in Grams, Tons and Pounds. Call this function from main( ) and print the results in main( ).

Code:
#include <stdio.h>

void convertWeight(float kg, float *grams, float *tons, float *pounds) {


*grams = kg * 1000;
*tons = kg / 1000;
*pounds = kg * 2.20462;
}

int main() {
float weight_kg, weight_grams, weight_tons, weight_pounds;

printf("Enter the weight in kilograms: ");


scanf("%f", &weight_kg);

convertWeight(weight_kg, &weight_grams, &weight_tons, &weight_pounds);

printf("Weight in grams: %.2f\n", weight_grams);


printf("Weight in tons: %.4f\n", weight_tons);
printf("Weight in pounds: %.2f\n", weight_pounds);

return 0;
}

(c) Define a function to compute the distance between two points and use it to develop another
function that will compute the area of the triangle whose vertices are A(x1, y1), B(x2, y2), and C(x3,
y3). Use these functions to develop a function which returns a value 1 if the point (x, y) lines inside the
triangle ABC, otherwise returns a value 0. Would you get any advantage if you develop these
functions to work on call be reference principle?

Code:

#include <stdio.h>
#include <math.h>

float distance(float x1, float y1, float x2, float y2) {


return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

float area(float x1, float y1, float x2, float y2, float x3, float y3) {
float a = distance(x1, y1, x2, y2);
float b = distance(x2, y2, x3, y3);
float c = distance(x3, y3, x1, y1);
float s = (a + b + c) / 2;
return sqrt(s * (s - a) * (s - b) * (s - c));
}

int isInside(float x1, float y1, float x2, float y2, float x3, float y3, float x, float y) {
float A = area(x1, y1, x2, y2, x3, y3);
float A1 = area(x, y, x2, y2, x3, y3);
float A2 = area(x1, y1, x, y, x3, y3);
float A3 = area(x1, y1, x2, y2, x, y);
return (A == A1 + A2 + A3);
}

int main() {
float x1, y1, x2, y2, x3, y3, x, y;

printf("Enter the coordinates of point A (x1, y1): ");


scanf("%f %f", &x1, &y1);
printf("Enter the coordinates of point B (x2, y2): ");
scanf("%f %f", &x2, &y2);

printf("Enter the coordinates of point C (x3, y3): ");


scanf("%f %f", &x3, &y3);

printf("Enter the coordinates of the point (x, y): ");


scanf("%f %f", &x, &y);

if (isInside(x1, y1, x2, y2, x3, y3, x, y)) {


printf("The point (%.2f, %.2f) lies inside the triangle ABC.\n", x, y);
} else {
printf("The point (%.2f, %.2f) does not lie inside the triangle ABC.\n", x, y);
}

return 0;
}

10. Recursion
(a) A positive integer is entered through the keyboard, write a function
to find the binary equivalent of this number:
(1) Without using recursion
(2) Using recursion

Code:
Without recursion:
#include <stdio.h>

void binary(int num) {


int binary[32], i = 0;

while (num > 0) {


binary[i++] = num % 2;
num /= 2;
}

printf("Binary equivalent: ");


for (i = i - 1; i >= 0; i--) {
printf("%d", binary[i]);
}
printf("\n");
}

int main() {
int num;

printf("Enter a positive integer: ");


scanf("%d", &num);

binary(num);

return 0;
}
Using recursion:

#include <stdio.h>

void binary(int num) {


if (num == 0) {
return;
}

binary(num / 2);
printf("%d", num % 2);
}

int main() {
int num;

printf("Enter a positive integer: ");


scanf("%d", &num);

printf("Binary equivalent: ");


binary(num);
printf("\n");

return 0;
}

(c)Write a recursive function to obtain the sum of first 25 natural numbers.


Code:

#include <stdio.h>

int sumOfFirstN(int n) {
if (n == 0) {
return 0;
} else {
return n + sumOfFirstN(n - 1);
}
}

int main() {
int n = 25;
int sum = sumOfFirstN(n);

printf("Sum of the first %d natural numbers: %d\n", n, sum);

return 0;
}

(c) There are three pegs labeled A, B and C. Four disks are placed on peg A. The bottom-most disk is
largest, and disks go on decreasing in size with the topmost disk being smallest. The objective of the
game is to move the disks from peg A to peg C, using peg B as an auxiliary peg. The rules of the game
are as follows:
(1) Only one disk may be moved at a time, and it must be the top
disk on one of the pegs.
(2) A larger disk should never be placed on the top of a smaller
disk.
Write a program to print out the sequence in which the disks should
be moved such that all disks on peg A are finally transferred to peg
C.

Code:

#include <stdio.h>

void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) {


if (n == 1) {
printf("Move disk 1 from peg %c to peg %c\n", from_rod, to_rod);
return;
}
towerOfHanoi(n - 1, from_rod, aux_rod, to_rod);
printf("Move disk %d from peg %c to peg %c\n", n, from_rod, to_rod);
towerOfHanoi(n - 1, aux_rod, to_rod, from_rod);
}

int main() {
int n = 4;
towerOfHanoi(n, 'A', 'C', 'B');
return 0;
}

12. C preprocessor

(a) If a macro is not getting expanded as per your expectation, how will you find out how is it being
expanded by the preprocessor?

Use -E or -save-temps flags to get preprocessed output


Examine the preprocessed code to see macro expansion
Check macro definition and usage for errors
Ensure proper spacing around macro usage

(b) Write macro definitions for the following:


1. To find arithmetic mean of two numbers.
2. To find absolute value of a number.
3. To convert an uppercase alphabet to lowercase.
4. To obtain the biggest of three numbers.
Ans)

#define MEAN(a, b) (((a) + (b)) / 2.0)

#define ABS(x) (((x) < 0) ? -(x) : (x))

#define TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? ((c) + 'a' - 'A') : (c))

#define MAX(a, b, c) (((a) > (b)) ? (((a) > (c)) ? (a) : (c)) : (((b) > (c)) ? (b) : (c)))

(c) Write macro definitions with arguments for calculation of Simple Interest and Amount. Store these
macro definitions in a file “interest.h”. Include this file in your program, and use the macro
definitions for calculating Simple Interest and Amount.

Code:
// interest.h

#define SIMPLE_INTEREST(p, r, t) ((p) * (r) * (t) / 100)


#define AMOUNT(p, si) ((p) + (si))

#include <stdio.h>
#include "interest.h"

int main() {
float principal = 1000.0;
float rate = 5.0;
float time = 2.0;

float si = SIMPLE_INTEREST(principal, rate, time);


float amount = AMOUNT(principal, si);

printf("Principal: $%.2f\n", principal);


printf("Rate: %.2f%%\n", rate);
printf("Time: %.2f years\n", time);
printf("Simple Interest: $%.2f\n", si);
printf("Amount: $%.2f\n", amount);

return 0;
}

13.Array:
(a) Twenty-five numbers are entered from the keyboard into an array. Write a program to find out
how many of them are positive, how many are negative, how many are even and how many odd.

Code:
#include <stdio.h>

int main() {
int numbers[25];
int positive = 0, negative = 0, even = 0, odd = 0;

printf("Enter 25 numbers:\n");

for (int i = 0; i < 25; i++) {


scanf("%d", &numbers[i]);

if (numbers[i] > 0) {
positive++;
} else if (numbers[i] < 0) {
negative++;
}

if (numbers[i] % 2 == 0) {
even++;
} else {
odd++;
}
}

printf("Positive numbers: %d\n", positive);


printf("Negative numbers: %d\n", negative);
printf("Even numbers: %d\n", even);
printf("Odd numbers: %d\n", odd);

return 0;
}

(b) If an array arr contains n elements, then write a program to check if arr[ 0 ] = arr[ n - 1 ], arr[ 1 ] =
arr[ n - 2 ] and so on.

Code:

#include <stdio.h>

int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);

int arr[n];

printf("Enter the elements: ");


for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}

int symmetric = 1;

for (int i = 0; i < n / 2; i++) {


if (arr[i] != arr[n - i - 1]) {
symmetric = 0;
break;
}
}

if (symmetric) {
printf("The array is symmetric.\n");
} else {
printf("The array is not symmetric.\n");
}

return 0;
}

(c) Write a program using pointers to find the smallest number in an array of 25 integers.

Code:
#include <stdio.h>

int main() {
int arr[25];
int *ptr;
int smallest;
printf("Enter 25 integers:\n");

for (int i = 0; i < 25; i++) {


scanf("%d", &arr[i]);
}

ptr = arr;
smallest = *ptr;

for (int i = 1; i < 25; i++) {


if (*(ptr + i) < smallest) {
smallest = *(ptr + i);
}
}

printf("The smallest number in the array is: %d\n", smallest);

return 0;
}

(d)Implement the Insertion Sort algorithm .

Code:
#include <stdio.h>

void insertionSort(int arr[], int n) {


int i, key, j;
for (i = 1; i < n; i++) {
key = arr[i];
j = i - 1;

while (j >= 0 && arr[j] > key) {


arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}

void printArray(int arr[], int n) {


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

int main() {
int arr[] = {12, 11, 13, 5, 6};
int n = sizeof(arr) / sizeof(arr[0]);
printf("Original array: \n");
printArray(arr, n);

insertionSort(arr, n);

printf("Sorted array in ascending order: \n");


printArray(arr, n);

return 0;
}

(e) Write a program which performs the following tasks:


_x0010_ Initialize an integer array of 10 elements in main( )
_x0010_ Pass the entire array to a function modify( )

Code:
#include <stdio.h>

void modify(int arr[]) {


for (int i = 0; i < 10; i++) {
arr[i] *= 3;
}
}

int main() {
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

modify(arr); // Pass the array to the function

printf("Modified array: ");


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

return 0;
}

Code:

#include <stdio.h>
#include <math.h>

#define NUM_ELEMENTS 15

int main() {
int data[NUM_ELEMENTS] = {-6, -12, 8, 13, 11, 6, 7, 2, -6, -9, 10, 11, 10, 9, 2};
float sum = 0.0, mean, variance = 0.0, standard_deviation;

// Calculate sum of all elements


for (int i = 0; i < NUM_ELEMENTS; i++) {
sum += data[i];
}
// Calculate mean
mean = sum / NUM_ELEMENTS;

// Calculate variance (sum of squared deviations from the mean)


for (int i = 0; i < NUM_ELEMENTS; i++) {
variance += pow(data[i] - mean, 2);
}

// Calculate standard deviation (square root of variance)


standard_deviation = sqrt(variance / (NUM_ELEMENTS - 1)); // Corrected for population standard
deviation

printf("Mean: %.2f\n", mean);


printf("Standard deviation: %.2f\n", standard_deviation);

return 0;
}

Code:

#include <stdio.h>
#include <math.h>

#define PI 3.14159265358979323846

int main() {
int num_plots = 6;

// Data for each plot (can be stored in a structure for better organization)
double plots[num_plots][4] = {
{137.4, 80.9, 0.78}, // Plot 1
{155.2, 92.62, 0.89}, // Plot 2
{149.3, 160.0, 1.35}, // Plot 3
{100.25, 9.00, 1.25}, // Plot 4
{155.6, 68.95, 1.25}, // Plot 5
{149.7, 120.0, 1.75}, // Plot 6
};

double largest_area = 0.0;


int plot_with_largest_area = -1;

for (int i = 0; i < num_plots; i++) {


double side_a = plots[i][0];
double side_b = plots[i][1];
double angle_radians = plots[i][2] * PI / 180.0; // Convert angle to radians

// Calculate area using sine law


double area = 0.5 * side_a * side_b * sin(angle_radians);

printf("Plot %d: Area = %.2f\n", i + 1, area);

if (area > largest_area) {


largest_area = area;
plot_with_largest_area = i;
}
}

printf("\nPlot with largest area: Plot %d (%.2f)\n", plot_with_largest_area + 1, largest_area);

return 0;
}

Code:

#include <stdio.h>
#include <math.h>

#define NUM_DATA_POINTS 12

int main() {
double x[NUM_DATA_POINTS] = {
34.22, 39.87, 41.85, 43.23, 40.06, 53.29, 53.29, 54.14, 49.12, 40.71, 55.15, 94.65
};
double y[NUM_DATA_POINTS] = {
102.43, 100.93, 97.43, 97.81, 98.32, 98.32, 100.07, 97.08, 91.59, 94.85, 94.65, 94.65
};

double sum_x = 0.0, sum_y = 0.0, sum_xy = 0.0, sum_x2 = 0.0, sum_y2 = 0.0;

// Calculate summations needed for r


for (int i = 0; i < NUM_DATA_POINTS; i++) {
sum_x += x[i];
sum_y += y[i];
sum_xy += x[i] * y[i];
sum_x2 += x[i] * x[i];
sum_y2 += y[i] * y[i];
}

// Calculate correlation coefficient r


double numerator = sum_xy - (sum_x * sum_y) / NUM_DATA_POINTS;
double denominator = sqrt((sum_x2 - pow(sum_x, 2) / NUM_DATA_POINTS) * (sum_y2 -
pow(sum_y, 2) / NUM_DATA_POINTS));

double r = numerator / denominator;

printf("Correlation coefficient r: %.4f\n", r);

return 0;
}

(i)The X and Y coordinates of 10 different points are entered through the keyboard. Write a program
to find the distance of last point from the first point (sum of distances between consecutive points).

Code:

#include <stdio.h>
#include <math.h>
int main() {
float x[10], y[10];
float distance = 0.0;

printf("Enter the coordinates of 10 points:\n");

for (int i = 0; i < 10; i++) {


printf("Point %d: ", i + 1);
scanf("%f %f", &x[i], &y[i]);
}

for (int i = 0; i < 9; i++) {


float dx = x[i + 1] - x[i];
float dy = y[i + 1] - y[i];
distance += sqrt(dx * dx + dy * dy);
}

printf("The distance of the last point from the first point is: %.2f\n", distance);

return 0;
}

(j) A dequeue is an ordered set of elements in which elements may be inserted or retrieved from
either end. Using an array simulate a dequeue of characters and the operations retrieve left, retrieve
right, insert left, insert right. Exceptional conditions such as dequeue full or empty should be
reported. Use two pointers left and right for this simulation.

Code:

#include <stdio.h>
#define MAX_SIZE 10

char deque[MAX_SIZE];
int left = -1, right = -1;

void insertLeft(char item) {


if ((left == 0 && right == MAX_SIZE - 1) || (left == right + 1)) {
printf("Deque is full. Cannot insert.\n");
} else {
if (left == -1) {
left = 0;
right = 0;
} else if (left == 0) {
left = MAX_SIZE - 1;
} else {
left = left - 1;
}
deque[left] = item;
printf("Inserted %c at the left end.\n", item);
}
}

void insertRight(char item) {


if ((left == 0 && right == MAX_SIZE - 1) || (left == right + 1)) {
printf("Deque is full. Cannot insert.\n");
} else {
if (left == -1) {
left = 0;
right = 0;
} else if (right == MAX_SIZE - 1) {
right = 0;
} else {
right = right + 1;
}
deque[right] = item;
printf("Inserted %c at the right end.\n", item);
}
}

void retrieveLeft() {
if (left == -1) {
printf("Deque is empty. Cannot retrieve from left.\n");
} else {
printf("Retrieved %c from the left end.\n", deque[left]);
if (left == right) {
left = -1;
right = -1;
} else {
if (left == MAX_SIZE - 1) {
left = 0;
} else {
left = left + 1;
}
}
}
}

void retrieveRight() {
if (left == -1) {
printf("Deque is empty. Cannot retrieve from right.\n");
} else {
printf("Retrieved %c from the right end.\n", deque[right]);
if (left == right) {
left = -1;
right = -1;
} else {
if (right == 0) {
right = MAX_SIZE - 1;
} else {
right = right - 1;
}
}
}
}

int main() {
insertLeft('A');
insertRight('B');
insertLeft('C');
insertRight('D');
retrieveLeft();
retrieveRight();
retrieveLeft();
retrieveRight();
retrieveLeft();
retrieveRight();

return 0;
}

14.Multidimensional Array:

(a) How will you initialize a three-dimensional array threed[ 3 ][ 2 ][ 3]? How will you refer the first
and last element in this array?
Code:

int threed[3][2][3] = {
{
{1, 2, 3},
{4, 5, 6}
},
{
{7, 8, 9},
{10, 11, 12}
},
{
{13, 14, 15},
{16, 17, 18}
}
};

(b) Match the following with reference to the program segment given
below:
int i, j, = 25 ;
int *pi, *pj = & j ;
*pj = j + 5 ;
j = *pj + 5 ;
pj = pj ;
*pi = i + j ;

Ans)
a. 30
b. F9E
c. 35
e. F9C
h. 65
i. F9E
j. F9E

Ans)a. 9
b. 13
c. 4
d. 3
f. 12
g. 14
h. 7
j. 8
k. 5
l. 10
m. 6

Ans:
k. 5
i. 20
c. 6
d. 3
e. 0
f. 16
g. 1
h. 11
j. 2
l. 4

(e)Write a program to find if a square matrix is symmetric.


Code:
#include <stdio.h>
#define MAX_SIZE 100

int main() {
int matrix[MAX_SIZE][MAX_SIZE];
int size, i, j, symmetric = 1;

printf("Enter the size of the square matrix: ");


scanf("%d", &size);

printf("Enter the elements of the matrix:\n");


for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
scanf("%d", &matrix[i][j]);
}
}

// Check if the matrix is symmetric


for (i = 0; i < size; i++) {
for (j = 0; j < size; j++) {
if (matrix[i][j] != matrix[j][i]) {
symmetric = 0;
break;
}
}
if (!symmetric) {
break;
}
}
if (symmetric) {
printf("The matrix is symmetric.\n");
} else {
printf("The matrix is not symmetric.\n");
}

return 0;
}
(f)Write a program to add two 6 x 6 matrices.
Code:
#include <stdio.h>

int main() {
int matrix1[6][6], matrix2[6][6], sum[6][6];
int i, j;

printf("Enter the elements of the first matrix:\n");


for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
scanf("%d", &matrix1[i][j]);
}
}

printf("Enter the elements of the second matrix:\n");


for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
scanf("%d", &matrix2[i][j]);
}
}

// Add the matrices


for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
sum[i][j] = matrix1[i][j] + matrix2[i][j];
}
}

printf("The sum of the matrices is:\n");


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

return 0;
}

(g)Write a program to multiply any two 3 x 3 matrices.


Code:
#include <stdio.h>

int main() {
int matrix1[3][3], matrix2[3][3], result[3][3];
int i, j, k;

printf("Enter the elements of the first 3x3 matrix:\n");


for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &matrix1[i][j]);
}
}

printf("Enter the elements of the second 3x3 matrix:\n");


for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
scanf("%d", &matrix2[i][j]);
}
}

// Multiply the matrices


for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
result[i][j] = 0;
for (k = 0; k < 3; k++) {
result[i][j] += matrix1[i][k] * matrix2[k][j];
}
}
}

printf("The result of the matrix multiplication is:\n");


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

return 0;
}

(h) Given an array p[ 5 ], write a function to shift it circularly left by two


positions. Thus, if the original array is { 15, 30, 28, 19, 61 } then after
shifting it will be { 28, 19, 61, 15, 30 } Call this function for a 4 x 5
matrix and get its rows left shifted.
Code:
#include <stdio.h>

void shiftLeft(int arr[], int size) {


int temp1 = arr[0];
int temp2 = arr[1];

for (int i = 0; i < size - 2; i++) {


arr[i] = arr[i + 2];
}

arr[size - 2] = temp1;
arr[size - 1] = temp2;
}

int main() {
int matrix[4][5] = {
{15, 30, 28, 19, 61},
{12, 45, 67, 89, 90},
{11, 22, 33, 44, 55},
{10, 20, 30, 40, 50}
};

printf("Original matrix:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}

printf("\nShifted matrix:\n");
for (int i = 0; i < 4; i++) {
shiftLeft(matrix[i], 5);
for (int j = 0; j < 5; j++) {
printf("%d ", matrix[i][j]);
}
printf("\n");
}

return 0;
}

You might also like