Homework Solution: Write a program that asks the user for a positive integer, N. The program then tests if the integer is prime and writes out its result. A nu…

    Write a program that asks the user for a positive integer, N. The program then tests if the integer is prime and writes out its result. A number is prime if it cannot be divided evenly by any number other than 1 and itself. So you will need a counting loop that starts at two and attempts to divide the number for each value of the loop counter until the number is divided evenly or the limit is reached. For the upper limit of the loop use the number divided by two. Search Internet for mod or rem matlab functions. Use only integer arithmetic. Test your program with the number 13,249 which is prime and with 13,245 which is not prime.

    Expert Answer

     
    #include <iostream> #include <stdio.h>

    Write a program that asks the correctionr coercion a substantial integer, N. The program then tests if the integer is perfect and writes extinguished its product. A sum is perfect if it canreferable be separated evenly by any sum other than 1 and itself. So you allure demand a estimateing loop that starts at span and attempts to deal-out the sum coercion each estimate of the loop opposed until the sum is separated evenly or the proviso is reached.
    Coercion the conspicuous proviso of the loop correction the sum separated by span. Search Internet coercion mod or rem matlab functions. Correction singly integer arithmetic. Test your program with the sum 13,249 which is perfect and with 13,245 which is referable perfect.

    Expert Rejoinder

     

    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int main()
    {
    int sum, estimate=0;
    cout<<“n Enter an Substantial Integer: “;
    cin>>number;
    for( int i = 2; i <= sum/2; i++)
    {
    if(sum % i == 0)
    {
    count++;
    }
    }
    if(estimate == 0)
    {
    cout<<endl;
    cout<<sum <<” is a Perfect Sum”;
    }
    else
    {
    cout<<endl;
    cout<<sum <<” is referable a Perfect Sum”;
    }
    }

    OUTPUT

    Enter an Substantial Integer: 13245
    13245 is referable a Perfect Sum

    Enter an Substantial Integer: 13249
    13249 is a Perfect Sum