C Program for Menu Driven Leap Year and Sum of Digits

In this program, you'll learn menu driven program to find leap year and sum of digits.



Source Code
# include <stdio.h>
# include <conio.h>
void main ()
{
    int ch=0,year;
    int rem=0,sum=0,num;
    // clrscr();
    printf("1. To find leap year\n");
    printf("2. To print sum of digits of a number\n");
    printf("Enter a choice : ");
    scanf ("%d",&ch);

    switch(ch)
    {
        case 1:
            printf("Enter year: ");
            scanf("%d", &year);
            if(year%4 == 0)
                printf("Its a leap year ");
            else
                printf("Its not a leap year ");
            break;

        case 2:
            printf("Enter a number: ");
            scanf("%d", &num);
            while(num != 0)
            {
                rem = num % 10;
                sum = sum + rem;
                num = num / 10;
            }
            printf("Sum of Digits is %d",sum);
            break;

        default:
            printf("Invalid choice!!!");
            break;
    }
}
Output
1. To find leap year
2. To print sum of digits of a number
Enter a choice : 1
Enter year: 1958
Its not a leap year

1. To find leap year
2. To print sum of digits of a number
Enter a choice : 2
Enter a number: 287
Sum of Digits is 17