Q1.
Write a C program to accept dimensions of a cylinder and display the surface area and
volume of cylinder. [15 Marks]
#include <stdio.h>
int main() {
double radius, height;
const double PI = 3.14159265;
// Input the dimensions
printf("Enter the radius of the cylinder: ");
scanf("%lf", &radius);
printf("Enter the height of the cylinder: ");
scanf("%lf", &height);
// Calculate the surface area and volume
double surface_area = 2 * PI * radius * (radius + height);
double volume = PI * radius * radius * height;
// Display the results
printf("Surface Area of the Cylinder: %.2lf square units\n", surface_area);
printf("Volume of the Cylinder: %.2lf cubic units\n", volume);
return 0;
}
Write a C program to accept temperatures in Fahrenheit (F) and display it in Celsius(C)
and Kelvin (K) (Hint: C=5.0/9(F-32), K = C+ 273.15) |15 Marks]
#include <stdio.h>
int main() {
double fahrenheit, celsius, kelvin;
// Input temperature in Fahrenheit
printf("Enter temperature in Fahrenheit: ");
scanf("%lf", &fahrenheit);
// Convert Fahrenheit to Celsius
celsius = (5.0 / 9) * (fahrenheit - 32);
// Convert Celsius to Kelvin
kelvin = celsius + 273.15;
// Display the results
printf("Temperature in Celsius: %.2lf degrees Celsius\n", celsius);
printf("Temperature in Kelvin: %.2lf Kelvin\n", kelvin);
return 0;
}
Write a menu driven program to perform the following operations on strings using
standard
library functions: (25 Marks] 1. Length of String 2. Copy String 3. Connect Two Strings 4.
Compare two strings
#include <stdio.h>
#include <string.h>
int main() {
int choice;
char str1[100], str2[100];
while (1) {
printf("\nString Operations Menu:\n");
printf("1. Length of String\n");
printf("2. Copy String\n");
printf("3. Connect Two Strings\n");
printf("4. Compare Two Strings\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter a string: ");
scanf("%s", str1);
printf("Length of the string: %lu\n", strlen(str1));
break;
case 2:
printf("Enter a source string: ");
scanf("%s", str1);
strcpy(str2, str1);
printf("Copied string: %s\n", str2);
break;
case 3:
printf("Enter the first string: ");
scanf("%s", str1);
printf("Enter the second string: ");
scanf("%s", str2);
strcat(str1, str2);
printf("Concatenated string: %s\n", str1);
break;
case 4:
printf("Enter the first string: ");
scanf("%s", str1);
printf("Enter the second string: ");
scanf("%s", str2);
if (strcmp(str1, str2) == 0) {
printf("Both strings are equal.\n");
} else {
printf("Strings are not equal.\n");
break;
case 5:
printf("Exiting the program.\n");
return 0;
default:
printf("Invalid choice. Please select a valid option.\n");
break;
return 0;
Write a C Program to accept a character from the keyboard and display its previous and
next character in order. Ex. If character entered is 'd', display "The previous character is c",
The next character is e". [15 Marks]
#include <stdio.h>
int main() {
char inputChar;
// Input a character from the user
printf("Enter a character: ");
scanf(" %c", &inputChar);
// Calculate the previous and next characters
char prevChar = inputChar - 1;
char nextChar = inputChar + 1;
// Display the results
printf("The previous character is %c\n", prevChar);
printf("The next character is %c\n", nextChar);
return 0;
Write a program to accept a string and then count the occurrences of a specific character
of a
string. (25 Marks]
#include <stdio.h>
#include <string.h>
int main() {
char inputString[100];
char searchChar;
int count = 0;
// Input a string from the user
printf("Enter a string: ");
scanf("%s", inputString);
// Input the character to search for
printf("Enter the character to count: ");
scanf(" %c", &searchChar);
// Iterate through the string and count the occurrences of the specified character
for (int i = 0; i < strlen(inputString); i++) {
if (inputString[i] == searchChar) {
count++;
// Display the result
printf("The character '%c' occurs %d times in the string.\n", searchChar, count);
return 0;
A cashier has currency notes of denomination 1, 5 and 10. Write a C program to accept
the withdrawal amount from the user and display the total number of currency notes of
each
denomination the cashier will have to give. [
#include <stdio.h>
int main() {
int withdrawalAmount;
int notes10, notes5, notes1;
// Input the withdrawal amount
printf("Enter the withdrawal amount: ");
scanf("%d", &withdrawalAmount);
// Calculate the number of each denomination of currency notes
notes10 = withdrawalAmount / 10;
withdrawalAmount = withdrawalAmount % 10;
notes5 = withdrawalAmount / 5;
notes1 = withdrawalAmount % 5;
// Display the results
printf("Number of 10-rupee notes: %d\n", notes10);
printf("Number of 5-rupee notes: %d\n", notes5);
printf("Number of 1-rupee notes: %d\n", notes1);
return 0;
Write a menu driven program to perform the following operation on m*n Matrix [25
Marks]
1. Calculate sum of upper triangular matrix elements
2. Calculate sum of diagonal elements
#include <stdio.h>
int main() {
int m, n;
printf("Enter the number of rows (m) and columns (n) for the matrix: ");
scanf("%d %d", &m, &n);
if (m <= 0 || n <= 0) {
printf("Invalid matrix dimensions. Exiting the program.\n");
return 1;
int matrix[m][n];
// Input matrix elements
printf("Enter the matrix elements row-wise:\n");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
scanf("%d", &matrix[i][j]);
int choice;
while (1) {
printf("\nMatrix Operations Menu:\n");
printf("1. Calculate sum of upper triangular matrix elements\n");
printf("2. Calculate sum of diagonal elements\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
if (m != n) {
printf("The matrix is not square, so it doesn't have an upper triangular part.\n");
} else {
int sum = 0;
for (int i = 0; i < m; i++) {
for (int j = i; j < n; j++) {
sum += matrix[i][j];
printf("Sum of upper triangular matrix elements: %d\n", sum);
break;
case 2:
if (m != n) {
printf("The matrix is not square, so it doesn't have a diagonal.\n");
} else {
int sum = 0;
for (int i = 0; i < m; i++) {
sum += matrix[i][i];
printf("Sum of diagonal elements: %d\n", sum);
break;
case 3:
printf("Exiting the program.\n");
return 0;
default:
printf("Invalid choice. Please select a valid option.\n");
break;
return 0;
Write a C program to accept a character from the user and check whether the character is
a vowel or consonant.
#include <stdio.h>
int main() {
char character;
// Input a character from the user
printf("Enter a character: ");
scanf(" %c", &character);
// Check if the character is a vowel or consonant
if ((character >= 'a' && character <= 'z') || (character >= 'A' && character <= 'Z')) {
// Convert the character to lowercase to simplify the check
character = tolower(character);
if (character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u') {
printf("%c is a vowel.\n", character);
} else {
printf("%c is a consonant.\n", character);
} else {
printf("Invalid input. Please enter an alphabetic character.\n");
return 0;
Write a program to accept two numbers as range and display multiplication table of all
numbers within that range. (25 Marks]
#include <stdio.h>
int main() {
int start, end;
// Input the range from the user
printf("Enter the starting number of the range: ");
scanf("%d", &start);
printf("Enter the ending number of the range: ");
scanf("%d", &end);
if (start > end) {
printf("Invalid range. The starting number should be less than or equal to the ending number.\
n");
return 1;
// Display multiplication tables for numbers within the range
for (int i = start; i <= end; i++) {
printf("Multiplication table for %d:\n", i);
for (int j = 1; j <= 10; j++) {
printf("%d x %d = %d\n", i, j, i * j);
printf("\n");
return 0;
Write a C program to accept the x and y coordinate of a point and find the quadrant in
which the point lies.
#include <stdio.h>
int main() {
double x, y;
// Input the x and y coordinates from the user
printf("Enter the x-coordinate of the point: ");
scanf("%lf", &x);
printf("Enter the y-coordinate of the point: ");
scanf("%lf", &y);
// Determine the quadrant in which the point lies
if (x > 0 && y > 0) {
printf("The point (%.2lf, %.2lf) lies in the first quadrant.\n", x, y);
} else if (x < 0 && y > 0) {
printf("The point (%.2lf, %.2lf) lies in the second quadrant.\n", x, y);
} else if (x < 0 && y < 0) {
printf("The point (%.2lf, %.2lf) lies in the third quadrant.\n", x, y);
} else if (x > 0 && y < 0) {
printf("The point (%.2lf, %.2lf) lies in the fourth quadrant.\n", x, y);
} else if (x == 0 && y != 0) {
printf("The point (%.2lf, %.2lf) lies on the y-axis.\n", x, y);
} else if (x != 0 && y == 0) {
printf("The point (%.2lf, %.2lf) lies on the x-axis.\n", x, y);
} else {
printf("The point (%.2lf, %.2lf) is the origin (0,0).\n", x, y);
return 0;
Write a program, which accepts a number n and displays each digit in words. Example:
6702 Output - Six-Seven-Zero-Two [25 Marks|
#include <stdio.h>
// Character array to store the words for the digits
char words[10][10] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};
int main() {
int n;
// Accept the number n from the user
printf("Enter a number: ");
scanf("%d", &n);
// Extract the last digit of n and store it in a variable
int digit = n % 10;
// Use a switch statement to print the word for the digit
switch (digit) {
case 0:
printf("%s ", words[0]);
break;
case 1:
printf("%s ", words[1]);
break;
case 2:
printf("%s ", words[2]);
break;
case 3:
printf("%s ", words[3]);
break;
case 4:
printf("%s ", words[4]);
break;
case 5:
printf("%s ", words[5]);
break;
case 6:
printf("%s ", words[6]);
break;
case 7:
printf("%s ", words[7]);
break;
case 8:
printf("%s ", words[8]);
break;
case 9:
printf("%s ", words[9]);
break;
default:
printf("Invalid digit");
// Remove the last digit from n by dividing it by 10
n /= 10;
// Repeat steps 3-5 until n becomes 0
while (n > 0) {
digit = n % 10;
switch (digit) {
case 0:
printf("%s ", words[0]);
break;
case 1:
printf("%s ", words[1]);
break;
case 2:
printf("%s ", words[2]);
break;
case 3:
printf("%s ", words[3]);
break;
case 4:
printf("%s ", words[4]);
break;
case 5:
printf("%s ", words[5]);
break;
case 6:
printf("%s ", words[6]);
break;
case 7:
printf("%s ", words[7]);
break;
case 8:
printf("%s ", words[8]);
break;
case 9:
printf("%s ", words[9]);
break;
default:
printf("Invalid digit");
n /= 10;
printf("\n");
return 0;