Saturday, February 26, 2011
0
C Program Language (Switch Loop - Calendar)
This time we will going create a program using switch looping and the example activity is the calender with their corresponding days. This is the sample problem
Create a program that will ask the user to enter a number from 1-12 then print its corresponding month and count o days, otherwise it will print INVALID INPUT! (Use SWITCH)
Ex. Enter number (1-12): 3
March has 31 days
Here is the sample output for the user inputed numbers from 1-12 and a statement if the user will repeat or terminate.
And the another output below shows invalid input and again the program ask the user to repeat again or terminate.
The codes will be shown below for these program.
#include<stdio.h> #include<conio.h> main() { int mon; printf("Enter number ( 1 - 12 ): "); scanf("%d",&mon); switch(mon) { case 1: printf("January has 31 days"); break; case 2: printf("February has 28 days"); break; case 3: printf("March has 31 days"); break; case 4: printf("April has 30 days"); break; case 5: printf("May has 31 days"); break; case 6: printf("June has 30 days"); break; case 7: printf("July has 31 days"); break; case 8: printf("August has 31 days"); break; case 9: printf("September has 30 days"); break; case 10: printf("October has 31 days"); break; case 11: printf("November has 30 days"); break; case 12: printf("December has 31 days"); break; default: printf("INVALID INPUT! "); } getch(); }
Subscribe to:
Post Comments (Atom)
0 Responses to “C Program Language (Switch Loop - Calendar)”
Post a Comment