In this program, you'll learn menu driven program to find leap year and sum of digits.
# include <iostream>
using namespace std;
int main ()
{
int ch=0,year;
int rem=0,sum=0,num;
// ;
cout<<"1. To find leap year\n";
cout<<"2. To print sum of digits of a number\n";
cout<<"Enter a choice : ";
cin>> ch;
switch(ch)
{
case 1:
cout<<"Enter year: ";
cin>>year;
if(year%4 == 0)
cout<<"Its a leap year ";
else
cout<<"Its not a leap year ";
break;
case 2:
cout<<"Enter a number: ";
cin>>num;
while(num != 0)
{
rem = num % 10;
sum = sum + rem;
num = num / 10;
}
cout<<"Sum of Digits is " << sum;
break;
default:
cout<<"Invalid choice!!!";
break;
}
return 0;
}
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