Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Write a program that replies either Leap Year or Not a Leap Year, given a ye

ID: 3791580 • Letter: C

Question


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 only (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 t 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.

Explanation / Answer

"1. Leap year or not"

#include <iostream>
using namespace std;

int main()
{
int year;

cout << "Enter a year: ";
cin >> year;

if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
cout << year << " is a leap year.";
else
cout << year << " is not a leap year.";
}
else
cout << year << " is a leap year.";
}
else
cout << year << " is not a leap year.";

return 0;
}

"2. Prime number or not"

#include <iostream>
#include <cctype>
using namespace std;

int main(){
int n,i=1,sum=0;
cout << "Enter a number: ";
cin >> n;
cout<<" Divisors of number are : ";
while(i<n){
if(n%i==0)
{
cout<<i<< " ";
sum=sum+i;
}
i++;
}

if(sum==n)
cout << endl<<n<<" is a perfect number ";
else
cout << i << " is not a perfect number ";
system("pause");

return 0;
}

"3. "


#include <iostream>
#include <cctype>
using namespace std;

int main(){
int low,high,num,sum=0, check=0,cube=0;
cout << "Enter a lower limit: ";
cin >> low;
cout << "Enter a higher limit : ";
cin >> high;
cout<<" calculating.... "<<endl;
  
while(low<=high){
num=low;
           while ( num > 0 ) {
           cube=0;
           //cout<<num<< " ";
           sum = num % 10;
           cube += (sum * (sum*sum)) ; //calculating cube of each digit
           num /= 10;
           check+=cube;       //adding sum of cubes of digits
          
           }
          
           if (low==check) //checkng sum of cube of digits to number
cout << low <<" ==> sum is "<< check<< "==>"<< low<<" is equal to sum of cube of its digits"<<endl;
  
   check=0;         
low++;
       }


return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote