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

c program: Repeatedly query the user for positive integer and determine the foll

ID: 3769826 • Letter: C

Question

c program: Repeatedly query the user for positive integer and determine the following for each value: a. Is the value a multiple of 7, 11, or 13? (Yes or No) b. Is the sum of the digits of the integer even or odd? c. Is the value a prime number? (Yes or No) Main must prompt the user for the value and pass that value to a single function which computes the answers to all three questions, returning the three results to main as output (reference) parameters. Main then displays the results and queries the user for another value, repeating the process until a sentinel value is reached. Your solution MUST use a single function with three output (reference) parameters; other solutions will not be accepted.

Explanation / Answer


#include<stdio.h>
int main()
{

int m_check=2,p_check=2,s_check=2,t=0,val;
do
{
printf("Enter any positive integer:(press -1 to quit ");
scanf("%d",&val);
if((val>=0)&&(val!=-1))
{
m_check=999;
compute(val,&m_check,&s_check,&p_check);
if(m_check==1)
printf("YES , the no. is a multiple of 7 or 11 or 13 ");
else
printf("NO, the no. is not a multiple of 7 or 11 or 13 ");
if(s_check==0)
printf("YES, the sum of digits of no. is even ");
else
printf("NO, the sum of no.is not even ");
if(p_check==1)
printf("YES, the no. is prime ");
else
printf("NO, the no. is not prime ");
}

else if(val==-1)
{
t=1;
break;
}
else
printf("only postive no. allowed ");

}while(t==0);
}
void compute(int v,int *mul_check,int *sum_check,int *prime_check)
{
int num,rem,sum=0,k,m=0;
if((v%7==0)||(v%11==0)||(v%13==0))
*mul_check=1;
num=v;
while(num>0)
{
rem=num%10;
sum+=rem;
num=num/10;
}
if(sum%2==0)
*sum_check=0;
else
*sum_check=1;
k=2;
while(k<v)
{
if(v%k==0)
{
m=1;
*prime_check=0;
break;
}
k++;
}
if(m==0)
*prime_check=1;

}

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