1. What are the different types of loops in decision making?
2. Differentiate break and continue statement.
3. What is local variable and global variable?
4. List the various types of branching statements.
5. Differentiate While Do Loop and Do While Loop.
6. What is strlen() function? Explain with example.
Write a C program to determine the price of a movie ticket based on a person’s age and whether
they are a member of a movie club using nested if-else statement to calculate and print the ticket
price based on the person’s age and membership status.
. The pricing rules are as follows:
1. If the person is a member of the movie club:
o If the age is between 0 and 12, the ticket price is Rs.5.
o If the age is between 13 and 60, the ticket price is Rs.10.
o If the age is above 60, the ticket price is Rs.7.
2. If the person is not a member:
o If the age is between 0 and 12, the ticket price is Rs.8.
o If the age is between 13 and 60, the ticket price is Rs.15.
o If the age is above 60, the ticket price is Rs.10.
#include <stdio.h>
int main()
int age;
char membership;
// Input age and membership status
printf("Enter your age: ");
scanf("%d", &age);
printf("Are you a member of the movie club? (y/n): ");
scanf(" %c", &membership); // Note the space before %c to consume any leftover newline
character
// Determine the ticket price based on membership and age using nested if-else
if (membership == 'y' || membership == 'Y') { // If the person is a member
if (age >= 0 && age <= 12) {
printf("Ticket price: $5\n");
else if (age >= 13 && age <= 60) {
printf("Ticket price: $10\n");
else if (age > 60) {
printf("Ticket price: $7\n");
else {
printf("Invalid age.\n");
else if (membership == 'n' || membership == 'N') { // If the person is not a member
if (age >= 0 && age <= 12) {
printf("Ticket price: $8\n");
else if (age >= 13 && age <= 60) {
printf("Ticket price: $15\n");
else if (age > 60) {
printf("Ticket price: $10\n");
else {
printf("Invalid age.\n");
}
}
else {
printf("Invalid membership input.\n");
return 0;
Write a C program with flowchart to display the name of the day based on the number entered by
the user. The program should prompt the user to enter a number (1 to 7), where each number
corresponds to a specific day of the week.
The program should use a switch-case statement to display the corresponding day:
1 - Monday
2 - Tuesday
3 - Wednesday
4 - Thursday
5 - Friday
6 - Saturday
7 - Sunday
If the user enters a number outside the range of 1 to 7, the program should display an error
message saying "Invalid input, please enter a number between 1 and 7."
#include <stdio.h>
int main() {
int day;
// Prompt the user to enter a number
printf("Enter a number (1-7) to display the corresponding day of the week: ");
scanf("%d", &day);
// Use a switch-case statement to display the day
switch (day) {
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;
case 7:
printf("Sunday\n");
break;
default:
printf("Invalid input, please enter a number between 1 and 7.\n");
break;
return 0;
A Cartesian coordinate system has 4 quardants. Write C program to find the quadrant of the
coordinate points given by the user, using both if-else and nested if-else control structure.
#include <stdio.h>
int main() {
float x, y;
// Input the coordinate point
printf("Enter the x-coordinate: ");
scanf("%f", &x);
printf("Enter the y-coordinate: ");
scanf("%f", &y);
printf("\nUsing if-else structure:\n");
// Using if-else structure
if (x > 0 && y > 0) {
printf("The point (%.2f, %.2f) is in Quadrant 1.\n", x, y);
} else if (x < 0 && y > 0) {
printf("The point (%.2f, %.2f) is in Quadrant 2.\n", x, y);
} else if (x < 0 && y < 0) {
printf("The point (%.2f, %.2f) is in Quadrant 3.\n", x, y);
} else if (x > 0 && y < 0) {
printf("The point (%.2f, %.2f) is in Quadrant 4.\n", x, y);
} else if (x == 0 && y == 0) {
printf("The point (%.2f, %.2f) is at the Origin.\n", x, y);
} else if (x == 0) {
printf("The point (%.2f, %.2f) lies on the Y-axis.\n", x, y);
} else if (y == 0) {
printf("The point (%.2f, %.2f) lies on the X-axis.\n", x, y);
printf("\nUsing nested if-else structure:\n");
// Using nested if-else structure
if (x == 0 && y == 0) {
printf("The point (%.2f, %.2f) is at the Origin.\n", x, y);
} else if (x == 0) {
printf("The point (%.2f, %.2f) lies on the Y-axis.\n", x, y);
} else if (y == 0) {
printf("The point (%.2f, %.2f) lies on the X-axis.\n", x, y);
} else {
if (x > 0) {
if (y > 0) {
printf("The point (%.2f, %.2f) is in Quadrant 1.\n", x, y);
} else {
printf("The point (%.2f, %.2f) is in Quadrant 4.\n", x, y);
} else {
if (y > 0) {
printf("The point (%.2f, %.2f) is in Quadrant 2.\n", x, y);
} else {
printf("The point (%.2f, %.2f) is in Quadrant 3.\n", x, y);
return 0;
Write a c program to swap two numbers and call by reference, where the actual memory
addresses (or references) of the variables are passed to the function and also allows the function
to directly modify the original values of the variables.
#include <stdio.h>
// Function to swap two numbers using call by reference
void swap(int *a, int *b) {
int temp;
temp = *a; // Store the value of 'a' in temp
*a = *b; // Assign the value of 'b' to 'a'
*b = temp; // Assign the value of temp to 'b'
int main() {
int num1, num2;
// Input two numbers
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Display numbers before swapping
printf("\nBefore swapping:\n");
printf("Number 1 = %d\n", num1);
printf("Number 2 = %d\n", num2);
// Call the swap function
swap(&num1, &num2);
// Display numbers after swapping
printf("\nAfter swapping:\n");
printf("Number 1 = %d\n", num1);
printf("Number 2 = %d\n", num2);
return 0;
}
Write a C program that calculates the sum of an array of integers. Instead of accessing the array
elements directly use a pointer to iterate through the array and calculate the sum.
1. Takes the size of the array as input from the user.
2. Takes the elements of the array as input.
3. Uses a pointer to calculate and display the sum of all the elements in the array.
#include <stdio.h>
int main() {
int size;
// Take the size of the array as input
printf("Enter the size of the array: ");
scanf("%d", &size);
int arr[size];
// Take the elements of the array as input
printf("Enter %d elements of the array:\n", size);
for (int i = 0; i < size; i++) {
scanf("%d", &arr[i]);
int sum = 0;
int *ptr = arr; // Pointer to the array
// Use the pointer to calculate the sum of the elements
for (int i = 0; i < size; i++) {
sum += *ptr; // Add the value pointed by the pointer
ptr++; // Move the pointer to the next element
// Display the sum
printf("The sum of the array elements is: %d\n", sum);
return 0;
A food ordering system asks the user to enter their choice between two items: "Pizza" and
"Burger." Write a program that compares the user’s input with these options and prints a message
based on their choice. If the user enters "Pizza," print "You ordered Pizza!" If the user enters
"Burger," print "You ordered Burger!" For any other input, print "Item not on the menu."
#include <stdio.h>
#include <string.h>
int main() {
char choice[20];
// Prompt the user to enter their choice
printf("Enter your choice (Pizza/Burger): ");
scanf("%19s", choice); // Reads the input into the choice variable
// Compare the user's choice with "Pizza" and "Burger"
if (strcmp(choice, "Pizza") == 0) {
printf("You ordered Pizza!\n");
} else if (strcmp(choice, "Burger") == 0) {
printf("You ordered Burger!\n");
} else {
printf("Item not on the menu\n");
}
return 0;
Write a C program to find grades of a student using else- if ladder. The subjects included in the
semester are Maths, Science, English, History and Geography. Each subject is valuated for 100
marks. Determine the grade of a student based on a percentage score achieved and print the grade
of the student.
i) if the student grade falls into the below category, grade them accordingly.
o If the grade is greater than or equal to 80, then “Your Grade : A+”.
o If the grade is greater than or equal to 75, then “Your Grade : A”.
o If the grade is greater than or equal to 60, then “Your Grade : B”.
o If the grade is greater than or equal to 45, then “Your Grade : C”.
o If the grade is greater than or equal to 35, then “Your Grade : D”.
ii) If the student doesn’t fall into any category then print “You Are Fail”.
#include<stdio.h>
void main()
int s1,s2,s3,s4,s5,t,p;
printf("\n Enter marks of 5 subjects each out of 100 ");
printf("\n\n Maths = ");
scanf("%d",&s1);
printf("\n Science = ");
scanf("%d",&s2);
printf("\n English = ");
scanf("%d",&s3);
printf("\n History = ");
scanf("%d",&s4);
printf("\n Geography = ");
scanf("%d",&s5);
t=s1+s2+s3+s4+s5; //Total
printf("\n Total marks = %d/500",t); p=t/5; //Percentage
printf("\n\n Percentage = %d%",p);
if(p>=80)
printf("\n\n Your Grade : A+");
else if(p>=75)
printf("\n\n Your Grade : A");
else if(p>=60)
printf("\n\n Your Grade : B");
else if(p>=45)
printf("\n\n Your Grade : C");
else if(p>=35)
printf("\n\n Your grade : D");
else printf("\n\n You Are Fail");
Sample Output
Enter marks of 5 subjects each out of 100
Maths = 80
Science = 78
English = 56
History = 90
Geography = 66
Total marks = 370/500
Percentage = 74
Your Grade : B
Write a C program with flowchart to display the name of the month entered by the user. The
program should use a switch-case statement to display the corresponding month based on the
number. If the user enters a number outside the range, the program should display a error
message saying " There is no month for this number"
#include<stdio.h>
void main()
{
int n;
printf("Month number:\n");
scanf("%d",&n);
switch(n)
case 1:
printf("The month name is January\n");
break;
case 2:
printf("The month name is February\n");
break;
case 3:
printf("The month name is March\n");
break;
case 4:
printf("The month name is April\n");
break;
case 5:
printf("The month name is May\n");
break;
case 6:
printf("The month name is June\n");
break;
case 7:
printf("The month name is July\n");
break;
case 8:
printf("The month name is August\n");break;
case 9:
printf("The month name is September\n");
break;
case 10:
printf("The month name is October\n");
break;
case 11:
printf("The month name is November\n");
break;
case 12:
printf("The month name is December\n");
break;
default:
printf("There is no month for this number\n");
break;
Sample Input and Output:
Month number:
The month name is February
Sample Input and Output:
Month number:
13
There is no month for this number
A teacher tries to relate between the Angles inscribed in a circle and the direction. Initially she
wants to teach them the directions related with the angle’s 0,90,180,270 indicating East, North,
West, South respectively. Write a C program using selection statement to denote the direction
graphically corresponding to the angle entered. If the user enters any unacceptable input, the
program should display an error message saying " Invalid"
Input Format: Input consists of a single integer corresponding to the angle entered by the student
Output Format: Output consists of the strings “North”, “South”, “East”, “West” and “Invalid”.
#include<stdio.h>
void main()
{
Int ang;
printf("Enter the angle:\n");
scanf("%d",&ang);
if(ang==0)
printf("%d corresponds to East",ang);
else if(ang==90)
printf("%d corresponds to North",ang);
else if(ang==180)
printf("%d corresponds to West",ang);
else if(ang==270)
printf("%d corresponds to South",ang);
else
printf("Invalid");
Sample input and output:
Enter the angle:
270
270 corresponds to South
Sample input and output:
Enter the angle:
375
Invalid
Write a c program to swap two numbers by call by value using function. Print the numbers before
swap operation and after swap operation as per format.
Sample Input & Output Format:
Before swap, value of a
Before swap, value of b
After swap, value of a
After swap, value of b
void swap(int x, int y)
int temp;
temp = x;
x = y;
y = temp;
printf("After swap, value of a : %d\n", x );
printf("After swap, value of b : %d\n", y );
#include <stdio.h>
void swap(int x, int y);
int main ()
int a = 100;
int b = 200;
printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );
swap(a, b);
return 0;
Sample Output:
Before swap, value of a :100
Before swap, value of b :200
After swap, value of a :200
After swap, value of b :100
Write a C program that sorts the given element in an ascending order
i) Initialize array size.
ii)Takes the elements of the array as input from user.
iii) Display the sorted elements in the array.
#include<stdio.h>
#include<conio.h>
void main()
int num[50],i,j,size,temp;
printf("Enter size of an array\n");
scanf("%d", &size);
printf("Enter Array elements\n");
for(i=0;i<size;i++)
scanf("%d",&num[i]);
for(i=0;i<size;i++)
for(j=i+1;j<size;j++)
if(num[i]>num[j])
{ temp=num[i];
num[i]=num[j];
num[j]=temp;
for(i=0;i<size;i++)
printf("%d\n",num[i]);
getch();
}
Sample Output:
Enter size of an array
Enter Array elements
33
22
55
11
44
The sorted array:
11
22
33
44
A cafe has introduced a digital menu system. When a customer enters two food names, the
system must check whether the customer entered the same item twice or two different items.
If the two names are the same, it should confirm the order. Otherwise, it should decide which item
comes first alphabetically to display the menu in sorted order. Write a C program to perform this
comparison using string handling functions.
Input Format: Input consists of a string1 and string2 entered by the user
Output Format: If strings are equal, then print "Both strings are equal”. If string1 is greater than
string2, then print " S1 is greater than S2”. Else print “S2 is greater than S1”
#include<stdio.h>
void main( )
char s1[20],s2[20];
printf("Enter the WORD1\n");
scanf("%s",s1);
printf("Enter the WORD2\n");
scanf("%s",s2);
if(strcmp(s1,s2)==0)
printf("Both strings are equal\n");
else if(strcmp(s1,s2)>0)
printf("S1 is greater than S2\n");
else
printf("S2 is greater than S1\n");
Sample Output
Enter the WORD1
pizza
Enter the WORD2
Pizza
S1 is greater than S2