0% found this document useful (0 votes)
30 views6 pages

Practical No 12

The document contains multiple C programming exercises, including printing the name of a month based on user input, displaying the corresponding day of the week, determining the type of triangle based on its sides, and identifying the season based on the month. Each exercise includes a detailed algorithm and corresponding C code implementation. The programs utilize switch statements for decision-making based on user input.

Uploaded by

sanskarshinde431
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)
30 views6 pages

Practical No 12

The document contains multiple C programming exercises, including printing the name of a month based on user input, displaying the corresponding day of the week, determining the type of triangle based on its sides, and identifying the season based on the month. Each exercise includes a detailed algorithm and corresponding C code implementation. The programs utilize switch statements for decision-making based on user input.

Uploaded by

sanskarshinde431
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/ 6

Practical No.

12

Exercise

1. Write a C program to print English Calendar months as


per given number (eg : If input is 4 then print “April”) using
Switch statement.

Algorithm:

1. Start.
2. Declare an integer variable month.
3. Input the month number (an integer between 1 and 12) from the user.
4. Switch on the value of the month variable:
o If month is 1, output "January".
o If month is 2, output "February".
o If month is 3, output "March".
o If month is 4, output "April".
o If month is 5, output "May".
o If month is 6, output "June".
o If month is 7, output "July".
o If month is 8, output "August".
o If month is 9, output "September".
o If month is 10, output "October".
o If month is 11, output "November".
o If month is 12, output "December".
o If month is any value other than 1 to 12, output "Invalid month number. Please
enter a number between 1 and 12."
5. End

#include <stdio.h>

int main() {

int month;

// Input month number

printf("Enter the month number (1 to 12): ");

scanf("%d", &month);

// Switch statement to print the month name

switch(month) {

case 1:

printf("January\n");

break;

case 2:
printf("February\n");

break;

case 3:

printf("March\n");

break;

case 4:

printf("April\n");

break;

case 5:

printf("May\n");

break;

case 6:

printf("June\n");

break;

case 7:

printf("July\n");

break;

case 8:

printf("August\n");

break;

case 9:

printf("September\n");

break;

case 10:

printf("October\n");

break;

case 11:

printf("November\n");

break;

case 12:

printf("December\n");
break;

default:

printf("Invalid month number. Please enter a number between 1 and 12.\n");

return 0;

2. Write a C program to Print days of week by taking number from 1 to 7.

#include <stdio.h>

int main() {

int day;

printf("Enter a number between 1 and 7 to get the corresponding day of the week: ");

scanf("%d", &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");

return 0;

Practical Related Questions

1. write a program to check whether the triangle is isosceles,


equilateral, scalene or Right-angled triangle.

#include <stdio.h>

int main() {

float a, b, c;

int triangleType = 0;

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

printf("Side a: ");

scanf("%f", &a);

printf("Side b: ");

scanf("%f", &b);

printf("Side c: ");

scanf("%f", &c);

if (a + b > c && a + c > b && b + c > a) {

if (a == b && b == c) {

triangleType = 1; // Equilateral

else if (a == b || b == c || a == c) {

triangleType = 2; // Isosceles
}

else if (a != b && b != c && a != c) {

triangleType = 3; // Scalene

if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) {

triangleType = 4; // Right-angled triangle

switch(triangleType) {

case 1:

printf("The triangle is Equilateral.\n");

break;

case 2:

printf("The triangle is Isosceles.\n");

break;

case 3:

printf("The triangle is Scalene.\n");

break;

case 4:

printf("The triangle is Right-angled.\n");

break;

default:

printf("Invalid triangle type.\n");

break;

} else {

printf("The given sides do not form a valid triangle.\n");

return 0;

2. Display the season -summer, winter, rain for given month of year.
#include<stdio.h>

int main() {

int month;

printf("Enter the month number (1 to 12): ");

scanf("%d", &month);

switch(month) {

case 12: // December

case 1: // January

case 2: // February

printf("Winter\n");

break;

case 3: // March

case 4: // April

case 5: // May

printf("Summer\n");

break;

case 6: // June

case 7: // July

case 8: // August

printf("Rain\n");

break;

case 9: // September

case 10: // October

case 11: // November

printf("Summer\n");

break;

default:

printf("Invalid month number. Please enter a number between 1 and 12.\n");

return 0;

You might also like