Write a C C++ program to find number of days in a month

Write a C C++ program to find number of days in a month

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

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

Flowchart to find number of days in a month

Flowchart to find number of days in months

C program to find number of days in a month

#include<stdio.h>
int main()
{
    int month;
    printf("Enter month number: ");
    scanf("%d",&month);
    switch(month)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        printf("31 days");
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        printf("30 days");
        break;
        case 2:
        printf("28 days");
        break;
        default:
        printf("Invalid month number");
    }
    return 0;
}

C++ program to find number of days in a month

#include<iostream>
using namespace std;
int main()
{
    int month;
    cout<<"Enter month number: ";
    cin>>month;
    switch(month)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
        cout<<"31 days";
        break;
        case 4:
        case 6:
        case 9:
        case 11:
        cout<<"30 days";
        break;
        case 2:
        cout<<"28 days";
        break;
        default:
        cout<<"Invalid month number";
    }
    return 0;
}

Output of C C++ program to find number of days in a month

Enter month number: 1
31 days
Enter month number: 6
30 days
Enter month number: 15
Invalid month number

Related programs in C and C++

  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. Switch between Mon to Sun (switch case single case)
  10. Checking vowel or consonant (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

Write a C C++ program to check vowel or consonant

Write a C C++ program to check vowel or consonant

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

C Language में उपलब्ध Operators और इनके विभिन्न प्रकारो को जानने के लिए देखें—Operators in C

Flowchart to check vowel or consonant

Find Vowel or Consonant flowchart

C program to check vowel or consonant

#include<stdio.h>
int main()
{
    char letter;
    printf("Enter a letter: ");
    scanf("%c",&letter);
    switch(letter)
    {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
        printf("Vowel");
        break;
        default:
        printf("Consonant");
    }
    return 0;
}

C++ program to check vowel or consonant

#include<iostream>
using namespace std;
int main()
{
    char letter;
    cout<<"Enter a letter: ";
    cin>>letter;
    switch(letter)
    {
        case 'a':
        case 'A':
        case 'e':
        case 'E':
        case 'i':
        case 'I':
        case 'o':
        case 'O':
        case 'u':
        case 'U':
        cout<<"Vowel";
        break;
        default:
        cout<<"Consonant";
    }
    return 0;
}

Output of C C++ program to check vowel or consonant

Enter a letter: A
Vowel
Enter a letter: Z
Consonant

Other branching statement programs in C C++

  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. Switch between Mon to Sun (switch case single case)
  10. Number of days in a month (switch case multiple case)
  11. Unconditional Branching (break continue and goto)
Share it to:

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:

Write a simple calculator program in C C++ using switch case

Write a simple calculator program in C C++ using switch case

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

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

Flowchart of simple calculator program using switch case

Simple calculator flowchart

Simple calculator program in C using switch case

#include<stdio.h>
int main()
{
    char choice;
    int n1,n2,res;
    printf("Enter choice: ");
    scanf("%c",&choice);
    printf("Enter two numbers: ");
    scanf("%d%d",&n1,&n2);
    switch(choice)
    {
        case '+':
        res=n1+n2;
        break;
        case '-':
        res=n1-n2;
        break;
        case '*':
        res=n1*n2;
        break;
        case '/':
        res=n1/n2;
        break;
        case '%':
        res=n1%n2;
        break;
        default:
        printf("Invalid choice");
    }
    printf("Result = %d",res);
    return 0;
}

Simple calculator program in C++ using switch case

#include<iostream>
using namespace std;
int main()
{
    char choice;
    int n1,n2,res;
    cout<<"Enter choice: ";
    cin>>choice;
    cout<<"Enter two numbers: ";
    cin>>n1>>n2;
    switch(choice)
    {
        case '+':
        res=n1+n2;
        break;
        case '-':
        res=n1-n2;
        break;
        case '*':
        res=n1*n2;
        break;
        case '/':
        res=n1/n2;
        break;
        case '%':
        res=n1%n2;
        break;
        default:
        cout<<"Invalid choice";
    }
    cout<<"Result = "<<res;
    return 0;
}

Output of simple calculator program in C C++ using switch case

Enter choice: +
Enter two numbers: 4 6
Result = 10
Enter choice: %
Enter two numbers: 10 6
Result = 4
Enter choice: #
Enter two numbers: 2 3
Invalid choice
Result = -53446 

Other switch case programs and branching programs in C C++

  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. Switch between Mon to Sun (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: