Logic:
- Enter day number
- Weekdays starts from Monday
- If day number=1, weekday is Monday
- If day number=2, weekday is Tuesday
- If day number=3, weekday is Wednesday
- If day number=4, weekday is Thursday
- If day number=5, weekday is Friday
- If day number=6, weekday is Saturday
- If day number=7, weekday is Sunday
- Otherwise, you have entered Wrong day number
Algorithm
- Enter day number as dno
- switch (dno)
- {
- case 1:
- printf(“monday”);
- break;
- case 2:
- printf(“tuesday”);
- break;
- case 3:
- printf(“wednesday”);
- break;
- case 4:
- printf(“thrusday”);
- break;
- case 5:
- printf(“friday”);
- break;
- case 6:
- printf(“saturday”);
- break;
- case 7:
- printf(“sunday”);
- break;
- default:
- printf(“wrong day”);
- }
Program
#include <stdio.h> int main() { printf("**********************************************************\n"); printf("**********************************************************\n"); printf("** WAP to enter a day number and tell weekday **\n"); printf("** Created by Sheetal Garg **\n"); printf("** Assistant Professor **\n"); printf("** Phone No:9467863365 **\n"); printf("**********************************************************\n"); printf("**********************************************************\n"); int dno; // day no. printf("enter day no."); scanf("%d", &dno); switch (dno) { case 1: printf("monday"); break; case 2: printf("tuesday"); break; case 3: printf("wednesday"); break; case 4: printf("thrusday"); break; case 5: printf("friday"); break; case 6: printf("saturday"); break; case 7: printf("sunday"); break; default: printf("wrong day"); } return 0; }
Output 1:
********************************************************** ********************************************************** ** WAP to enter a day number and tell weekday ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ********************************************************** ********************************************************** enter day no. 1 monday
Output 2:
********************************************************** ********************************************************** ** WAP to enter a day number and tell weekday ** ** Created by Sheetal Garg ** ** Assistant Professor ** ** Phone No:9467863365 ** ********************************************************** ********************************************************** enter day no. 8 wrong day