Question

(Please use C language, not C++) Determine the following information about each value in a list...

(Please use C language, not C++) Determine the following information about each value in a 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? (parameter output returns 0 for even, 1 for odd)

c. Is the value a prime number? (parameter output returns 0 nonprime, 1 for prime)

Use an output file for results. The goal is to implement both pass by value and pass by reference.

Typical Input could be: 104 3773 12 121 77 30751 -1

You main will look like this:

void main()

{

int value;

int multi, oddEven, prime;

getInput(&value);

while (value != -1)

{ multipleOf(value,&multi);

isOddEven(value, &oddEven);

isPrime(value, &prime)

printResults(value, multi, oddEven, prime);

getInput(&value);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//if you have any query then comment below.please rate the answer

#include<stdio.h>
void getInput(int *value)
{
int val;
printf("Enter value: ");
scanf("%d",&val);
*value=val;
}
void multipleOf(int value,int *multi)
{
if(value%7==0)
*multi=7;
if(value%11==0)
*multi=11;
if(value%13==0)
*multi=13;

}
void isOddEven(int num, int *oddEven)
{
int temp,sum=0,digit;
temp = num;
while (num > 0)
{
digit = num % 10;
sum = sum + digit;
num /= 10;
}
if(sum%2==0)
*oddEven=1;
else
*oddEven=0;
}
void isPrime(int n, int *prime)
{
int check = 0,j;
// Check whether n is prime or not
for(j=2;j<=n/2;j++)//for loop
{
if(n%j==0)
{
check = 1;
break;
}
}
if(check==0)
*prime=1;
else
*prime=0;
}
void printResults(int value,int multi,int oddEven,int prime)
{
printf("Value is: %d\n",value);
printf("Value is multiple of %d\n",multi);
printf("Value is EvenOdd %d ",oddEven);
if(oddEven)
printf("Odd\n");
else
printf("Even\n");
printf("value is Prime Or not: %d ",prime);
if(prime)
printf("Prime\n");
else
printf("Not Prime\n");

}

void main()

{

int value;
int multi=0, oddEven, prime;
getInput(&value);
while (value != -1)
{
multipleOf(value,&multi);
isOddEven(value, &oddEven);
isPrime(value, &prime);
printResults(value, multi, oddEven, prime);
getInput(&value);
}

}

Enter value: 12 alue is: 12 Jalue is multiple of 0 alue is EvenOdd Even alue is Prime Or notNot Prime Enter value: 45 alue is

Add a comment
Know the answer?
Add Answer to:
(Please use C language, not C++) Determine the following information about each value in a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C+ using pointers 2. Determine the following information about each value in a list of positive...

    C+ using pointers 2. Determine the following information about each value in a list of positive integers. Is the value a multiple of 7, 11, or 13? a. b. Is the sum of the digits odd or even? (parameter output returns 0 for even, 1 for odd) Is the value a prime number? (parameter output returns 0 nonprime, 1 for prime) c. You should write three functions: 1)input, 2) processing, 3)output 1) Input wil have one output parameter of type...

  • 3. [30pts] Determine the following information about a value passed in as a parameter. (a) Is...

    3. [30pts] Determine the following information about a value passed in as a parameter. (a) Is the value a multiple of 7, 11 or 13? (b) The sign of the value (-1 if it is negative, 0 if it is 0 and 1 if the value is positive). You should write a function with three type int parameters, one input parameter (the value) and two other output parameters. The function should send back the answers to the two questions above...

  • Write a C++ program that does the following : Define a class myInt that has as...

    Write a C++ program that does the following : Define a class myInt that has as its single attribute an integer variable and that contains member functions for determining the following information for an object of type myInt: A. Is it multiple of 7 , 11 , or 13. B. Is the sum of its digits odd or even. C. What is the square root value. D.Is it a prime number. E. Is it a perfect number ( The sum...

  • Use the language c++ and answer the followig questions: 1) Write a function that will take...

    Use the language c++ and answer the followig questions: 1) Write a function that will take an empty array of size 25 as input and modify each element such that the array stores values from 1 to 25. 2) Write a function to print this array to show your output. 3) Write a function to iterate through that array and print whether or not a number is: even, odd, and prime. ... Make sure to call your functions in main()...

  • Write a program that finds (ANSWER IN C LANGUAGE!): 1. The sum of all elements at...

    Write a program that finds (ANSWER IN C LANGUAGE!): 1. The sum of all elements at even subscripts 2. The sum of all elements at odd subscripts 3. The sum of all elements You are allowed to perform this functionality within main. Main program: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include <stdio.h> int main() { /* Declare array variables */ const int NUM_VALS = 4; int userValues[NUM_VALS]; int i; // counter int even = 0; int odd = 0; int sum = 0; /* Initialize...

  • C++ Functions can return a string, not just an int or a float. Write a function...

    C++ Functions can return a string, not just an int or a float. Write a function called everOrOdd which takes an integer parameter and returns either "Even" or "Odd" based on the value passed. In main, prompt the user for a number, called num, then pass num to evenOrOdd and display the returned value on the screen. Keep doing this until the user enters a zero. Use the following run as an example: Enter a number: 11 Odd Enter a...

  • 20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real l...

    20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real list that takes a list of integers and returns the same numbers converted to real. For example, if the input is [1,2,3], the output should be like [1.0,2.0,3.0 22. [5 points] Using foldr function, write a function duplist of type·a list 'a list that takes...

  • use c++ language, keep it simple i am using code block Exercise #2: Digitise a number...

    use c++ language, keep it simple i am using code block Exercise #2: Digitise a number Write the function digitiselint, int[]) of type int, which takes an integer N and finds all the digits of that integer and save them in an array. The function then returns the number of digits in N. Write the main() program that reads an integer, calls the function digitisel ), and prints the digits in reverse order. Sample input/output: Enter an integer: 2309456 The...

  • Please complete the following programming in C++ with clear explanations. Thanks! Primitive Types, Searching and Recursion...

    Please complete the following programming in C++ with clear explanations. Thanks! Primitive Types, Searching and Recursion a) Create a class Homework (in a file homework.h and homework.cpp). b) Create a function initialize_array that receives two parameters: an array of integers and the array size. Use a for loop and an if statement to put 1s in the odd positions of the array and 0s in the even positions. (Use pointers to pass an array of integers as parameter) c) Create...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT