Write a C C++ program to switch between Monday to Sunday

Write a C C++ program to switch between Monday to Sunday

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

Flowchart to switch between Monday to Sunday

Switch between Monday to Sunday flowchart

C program to switch between Monday to Sunday

#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;
}

C++ program to switch between Monday to Sunday

#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 of C C++ program to switch between Monday to Sunday

Enter day number: 1
Mon
Enter day number: 4
Thu
Enter day number: 7
Sun
Enter day number: 9
Invalid day number

Other related program of C and C++ on switch case

  1. Absolute value of number (simple if)
  2. Checking odd or even number (if else)
  3. Checking leap year (if else)
  4. Greater in two numbers (if else)
  5. Finding grade from percent (else if ladder)
  6. Total percent and division (else if ladder)
  7. Greatest in three numbers (nested if)
  8. Simple calculator program (switch case single case)
  9. Checking vowel or consonant (switch case multiple case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer