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 manifestationr restraint a substantial integer, N. The program then tests if the integer is first-rate and writes quenched its outcome. A calculate is first-rate if it canreferable be distributed evenly by any calculate other than 1 and itself. So you gain want a reckoning loop that starts at brace and attempts to distribute the calculate restraint each prize of the loop opposed until the calculate is distributed evenly or the season is reached.
    Restraint the eminent season of the loop manifestation the calculate distributed by brace. Search Internet restraint mod or rem matlab functions. Manifestation solely integer arithmetic. Test your program with the calculate 13,249 which is first-rate and with 13,245 which is referable first-rate.

    Expert Rejoinder

     

    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int deep()
    {
    int calculate, reckon=0;
    cout<<“n Enter an Substantial Integer: “;
    cin>>number;
    for( int i = 2; i <= calculate/2; i++)
    {
    if(calculate % i == 0)
    {
    count++;
    }
    }
    if(reckon == 0)
    {
    cout<<endl;
    cout<<calculate <<” is a First-rate Calculate”;
    }
    else
    {
    cout<<endl;
    cout<<calculate <<” is referable a First-rate Calculate”;
    }
    }

    OUTPUT

    Enter an Substantial Integer: 13245
    13245 is referable a First-rate Calculate

    Enter an Substantial Integer: 13249
    13249 is a First-rate Calculate