Exp 6 PPS Lab
Exp 6 PPS Lab
No:06
Programs using decision-making constructs: if-else, goto, switch-
case, break-continue.
1. Write a C program to determine eligibility for admission to a
professional course based on the following criteria: Marks in Maths
>=65 and Marks in Phy>=55 and Marks in Chem>=50 and Total in
all three subject >=190 or Total in Maths and Physics >=140.
Aim
Write a C program to determine eligibility for admission to a professional
course based on the subject mark using If-Else condition.
Algorithm
1. Start
2. Display Eligibility Criteria through Print Statement.
3. Get the Input Marks through Scan statement.
4. Calculate total mark of subjects using if-else condition.
5. Display Total Marks.
6. Check Eligibility of mark using if else condition.
7. End
Program
#include <stdio.h> // Include the standard input/output header file.
void main()
{
int p, c, m, t, mp; // Declare variables to store marks and totals.
if (m >= 65) // Check if marks in Maths are greater than or equal to 65.
if (p >= 55) // Check if marks in Physics are greater than or equal to 55.
if (c >= 50) // Check if marks in Chemistry are greater than or equal to 50.
if ((m + p + c) >= 190 || (m + p) >= 140) // Check if total marks criteria
are met.
printf("The candidate is eligible for admission.\n"); // Print eligibility
message.
else
printf("The candidate is not eligible.\n"); // Print ineligibility message.
else
printf("The candidate is not eligible.\n"); // Print ineligibility message.
else
printf("The candidate is not eligible.\n"); // Print ineligibility message.
else
printf("The candidate is not eligible.\n"); // Print ineligibility message.
}
Result
Thus eligibility of admission through mark I calculated using If-Else
Condition successfully.
Program
#include <stdio.h> // Include the standard input/output header file.
#include <string.h> // Include the string header file.
void main()
{
int custid, conu; // Declare variables to store customer ID and consumed
units.
float chg, surchg = 0, gramt, netamt; // Declare variables for charge,
surcharge, gross amount, and net amount.
char connm[25]; // Declare a character array to store customer name.
printf("Input Customer ID :"); // Prompt user for input of customer ID.
scanf("%d", &custid); // Read and store the customer ID.
printf("Input the name of the customer :"); // Prompt user for input of
customer name.
scanf("%s", connm); // Read and store the customer name.
printf("Input the unit consumed by the customer : "); // Prompt user for
input of consumed units.
scanf("%d", &conu); // Read and store the consumed units.
if (conu < 200)
chg = 1.20; // Set charge based on consumed units.
else if (conu >= 200 && conu < 400)
chg = 1.50; // Set charge based on consumed units.
else if (conu >= 400 && conu < 600)
chg = 1.80; // Set charge based on consumed units.
else
chg = 2.00; // Set charge based on consumed units.
gramt = conu * chg; // Calculate gross amount.
if (gramt > 300)
surchg = gramt * 15 / 100.0; // Calculate surcharge if gross amount is
greater than 300.
netamt = gramt + surchg; // Calculate net amount.
if (netamt < 100)
netamt = 100; // Set minimum net amount to 100.
printf("\nElectricity Bill\n");
printf("Customer IDNO :%d\n", custid);
printf("Customer Name :%s\n", connm);
printf("unit Consumed :%d\n", conu);
printf("Amount Charges @Rs. %4.2f per unit :%8.2f\n", chg, gramt);
printf("Surchage Amount :%8.2f\n", surchg);
printf("Net Amount Paid By the Customer :%8.2f\n", netamt);
}
Result
Thus the C program for calculating and displaying the electricity bill of a
given customer with sur charge is completed successfully.
Result
Thus the program to read any day number in integer and display the day
name was completed.
Aim
To write a C program which computes the area of various geometrical
shapes using switch statement.
Algorithm
1. Start the Program
2. Display options for the user to select the shape
3. Get the user choice and store it
4. Display the areas of various shapes using Switch statement.
5. Stop
Program
#include <stdio.h>
void main ()
{
int choice,r,l,w,b,h,s;
float area;
printf("Input 1 for area of circle\n");
printf("Input 2 for area of rectangle\n");
printf("Input 3 for area of triangle\n");
printf("Input 4 for area of square\n");
printf("Input your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Input radious of the circle : ");
scanf("%d",&r);
area=3.14*r*r;
break;
printf("The area is : %f\n",area);
case 2:
printf("Input length and width of the rectangle : ");
scanf("%d%d",&l,&w);
area=l*w;
break;
printf("The area is : %f\n",area);
case 3:
printf("Input the base and hight of the triangle :");
scanf("%d%d",&b,&h);
area=.5*b*h;
break;
printf("The area is : %f\n",area);
case 4:
printf("Input the side of the square :");
scanf("%d",&s);
area=s*s;
break;
printf("The area is : %f\n",area);
default:
printf("please choose from the given options.");
break;
}
Result
Thus C program to computes the area of various geometrical shapes using
a menu-driven approach is completed successfully.
Program
#include <stdio.h> // Include the standard input/output header file.
void main() {
int num1,num2,opt; // Declare variables to store user input and operation
choice.
// Prompt user for two integers and store them.
printf("Enter the first Integer :");
scanf("%d",&num1);
printf("Enter the second Integer :");
scanf("%d",&num2);
// Display the menu for operation choice.
printf("\nInput your option :\n");
printf("1-Addition.\n2-Substraction.\n3-Multiplication.\n4-Division.\n5-Exit.\
n");
scanf("%d",&opt); // Read and store the user's choice.
switch(opt) { // Start a switch statement based on the user's choice.
case 1:
printf("The Addition of %d and %d is: %d\n",num1,num2,num1+num2); //
Perform addition and print result.
break;
case 2:
printf("The Substraction of %d and %d is: %d\n",num1,num2,num1-num2);
// Perform subtraction and print result.
break;
case 3:
printf("The Multiplication of %d and %d is: %d\
n",num1,num2,num1*num2); // Perform multiplication and print result.
break;
case 4:
if(num2==0) {
printf("The second integer is zero. Divide by zero.\n"); // Handle division by
zero.
} else {
printf("The Division of %d and %d is : %d\n",num1,num2,num1/num2); //
Perform division and print result.
}
break;
case 5:
break; // Exit the program.
default:
printf("Input correct option\n"); // Display error message for invalid input.
break;
}
}
Result
Thus the C Program to perform a simple calculation using Menu-
Driven approach done using switch statement.
Aim
Write a C program to find whether a given number is odd or even using
goto statement.
Algorithm
1. Start
2. Declare Variables for simple calculation
3. Get the input from user.
4. Process the input using goto Statement and display the output.
5. Stop.
Program
#include<stdio.h>
#include<stdlib.h>
void main()
{
int num;
printf("Enter a number\n");
scanf("%d", &num);
if (num % 2 == 0)
goto even;
else
goto odd;
even:
printf("%d is even\n", num);
exit(0);
odd:
printf("%d is odd\n", num);
}
Result
Thus the program to find whether a given number is odd or even using goto
statement is completed.
Algorithm
1. Start the Program
2. Display options for the user to select the shape
3. Continue Loop work based on condition.
4. Display the message.
5. Break loop work based on condition
6. Stop.
Program
#include <stdio.h>
int main() {
printf("Using continue statement:\n");
return 0;
}
Result
Thus C program to print the values using break and continue statement
completed.