For C Write a program that replies either Leap Year or Not a


For C++
Write a program that replies either Leap Year or Not a Leap Year, given a year. It is a leap year if the year is divisible by 4 but not by 100 (for example, 1796 is a leap year because It is divisible by 4 but not by 100). A year that is divisible by both 4 and 100 is a leap year if it also divisible by 400 (for example, 2000 is a leap year, but 1800 is not A perfect number is a positive integer that is equal to the sum of its proper divisors. A proper divisor is a positive integer other than the number itself that divides the number evenly (i.e., no remainder) For example, 6 is a perfect number because the sum of its proper divisors 1, 2, and 3 is equal to 6. Eight is not a perfect number because 1 + 2 + 4 notequalto 8. Write a program that accepts a positive integer and determines whether the number is perfect. Also display all proper divisors of the number. Try a number between 20 and 30 and another number between 490 and 500. Write a program that displays all integers between low and high that are the sum of the cube of their digits In other words, find all numbers xyz such that xyz = x^3 + y^3 + z^3 for example 153 = 1^3 + 5^3 + 3^3. Try 100 for low and 1000 for high.

Solution

#include <iostream>
using namespace std;

int main() {
   int year;

       cout<<\"\ Enter the year \";
       cin>>year;

       if(year%4==0 && year%400==0 && year%100==0) // year divisible by 4,100 and 400
       cout<<\"\ Leap Year\"<<endl;

       else if((year%4==0 && year%100!=0) //year divisible by 4 and not by 100
       cout<<\"\ Leap Year\"<<endl;
     
       else
       cout<<\"\ Not a Leap Year\";
    
   return 0;
}

output:

2.

#include <iostream>
using namespace std;

int main()
{
   int number,i=1;
int sum = 0;
cout<<\"\ Enter a number\";
cin>>number;
  
   cout<<\"\ Divisors of number\";
   while(i<number)
   {
       if(number%i ==0) //number is divisible by i
       {
       sum = sum+i;    //sum
       cout<<\"\\t \"<<i;
       }
       i++;
   }

       if(sum == number)
       cout<<\"\ \"<<number<<\" is a perfect number\";
       else
       cout<<\"\ \"<<i<<\" is not a perfect number\";
  
     
    
   return 0;
}

output:

3.

#include <iostream>
using namespace std;

int main()
{
   int number,sumOfCube=0,rem,low,high,num;
   cout<<\"\ Enter low and high: \";
   cin>>low>>high;

   for(number= low+1;number<high;number++)//outer loop will execute from low+1 and high-1
   {
    num = number;
   sumOfCube =0;
   while(num>0 )   // calculate sum of cube of digits of number
     {
        rem=num%10;
       sumOfCube=sumOfCube+rem*rem*rem;;
     

       num/=10;
     }
     cout<<\"\ The cube sum of individual digits of \"<<number<<\" is: \"<<sumOfCube;
   }

     
    
   return 0;
}

output:

 For C++ Write a program that replies either Leap Year or Not a Leap Year, given a year. It is a leap year if the year is divisible by 4 but not by 100 (for exa
 For C++ Write a program that replies either Leap Year or Not a Leap Year, given a year. It is a leap year if the year is divisible by 4 but not by 100 (for exa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site