Write a C C++ program to switch between Mon to Sun

 

Flowchart

Switch between Monday to Sunday flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int day;
printf(“Enter day number: “);
scanf(“%d”,&day);
switch(day)
{
case 1:
printf(“Mon”);
break;
case 2:
printf(“Tue”);
break;
case 3:
printf(“Wed”);
break;
case 4:
printf(“Thu”);
break;
case 5:
printf(“Fri”);
break;
case 6:
printf(“Sat”);
break;
case 7:
printf(“Sun”);
break;
default:
printf(“Invalid day number”);
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int day;
cout<<“Enter day number: “;
cin>>day;
switch(day)
{
case 1:
cout<<“Mon”;
break;
case 2:
cout<<“Tue”;
break;
case 3:
cout<<“Wed”;
break;
case 4:
cout<<“Thu”;
break;
case 5:
cout<<“Fri”;
break;
case 6:
cout<<“Sat”;
break;
case 7:
cout<<“Sun”;
break;
default:
cout<<“Invalid day number”;
}
return 0;
}

 

Output

Switch between mon to sun output

 

Published by

admin

I am a computer teacher, programmer and web developer