Can anyone help me out with this problem? Determine the following information ab
ID: 3543282 • Letter: C
Question
Can anyone help me out with this problem?
Determine the following information about each value in list of positive integers:
a. is the value a multiple of 7, 11, or 13?
b. Is the sum of the digits odd or even?
c. Is the value a prime number?
You should write a function with three type int output parameters that send back the answers to these three questions.
Sample input data are:
104 3773 13 121 77 30751
Ask the user to enter a positive integer and signal they are finished with a sentinel value (chapter 6)
The function should send back answers through output parameters
1 if the number is a multiple of 7, 11 or 13 and 0 if it is not.
1 if the sum of the digits is odd and 0 if the sum of the digits is even
1 if the number is a prime number and zero if it is not.
.I need C programming no C++! And I have to use pointers, I would post some of my code, but I can't copy it :(
Explanation / Answer
#include<stdio.h>
#include<math.h>
int array[3];
int *check(int value)
{
int sum=0,r,i,value1;
//checking divisiblity with 7,11,13
if(value%7==0 || value%11==0 || value%13==0)
array[0]=1;
else
array[0]=0;
//sum of digits
value1=value;
for(;value1!=0;value1=value1/10)
{
r=value1%10;
sum=sum+r;
}
if(sum%2==0)
array[1]=0;
else
array[1]=1;
//checking prime or not
int sq = sqrt(value);
int flag=0;
for(i=2;i<sq;i++)
{
if(value%i==0)
{
flag=1;
break;
}
}
if(flag==1)
array[2]=0; //flag==1 means it is not prime
else
array[2]=1; //flag=0 means it is prime
return array; //return the pointer of the array
}
int main()
{
int sentinel=-1,scan,*oparray,i;
printf("Enter a number : ");
printf("Enter -1 to exit ");
scanf("%d",&scan);
while(scan!=sentinel)
{
oparray=check(scan); //oparray stores the pointer of the output array in the check function
printf("1 if the number is a multiple of 7, 11 or 13 and 0 if it is not. OUTPUT : %d ",oparray[0]);
printf("1 if the sum of the digits is odd and 0 if the sum of the digits is even OUTPUT : %d ",oparray[1]);
printf("1 if the number is a prime number and zero if it is not. OUTPUT : %d ",oparray[2]);
printf("Enter a number : ");
printf("Enter -1 to exit ");
scanf("%d",&scan);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.