194k views
1 vote
Write a program in c that reads a list of integers, and outputs whether the list contains all multiples of 10, no multiples of 10, or mixed values. Define a function named IsArrayMult10 that takes an array as a parameter, representing the list, and an integer as a parameter, representing the size of the list. IsArrayMult10() returns a boolean that represents whether the list contains all multiples of ten. Define a function named IsArrayNoMult10 that takes an array as a parameter, representing the list, and an integer as a parameter, representing the size of the list. IsArrayNoMult10() returns a boolean that represents whether the list contains no multiples of ten.

Then, write a main program that takes an integer, representing the size of the list, followed by the list values. The first integer is not in the list. Assume that the list will always contain less than 20 integers.


Ex: If the input is:


5 20 40 60 80 100

the output is:


all multiples of 10

Ex: If the input is:


5 11 -32 53 -74 95

the output is:


no multiples of 10

Ex: If the input is:


5 10 25 30 40 55

the output is:


mixed values

The program must define and call the following two functions. IsArrayMult10 returns true if all integers in the array are multiples of 10 and false otherwise. IsArrayNoMult10 returns true if no integers in the array are multiples of 10 and false otherwise.

bool IsArrayMult10(int inputVals[], int numVals)

bool IsArrayNoMult10(int inputVals[], int numVals)

User Raganwald
by
7.6k points

1 Answer

5 votes

Answer:

#include <stdio.h>

#include <stdbool.h>

bool IsArrayMult10(int inputVals[], int numVals) {

for (int i = 0; i < numVals; i++) {

if (inputVals[i] % 10 != 0) {

return false;

}

}

return true;

}

bool IsArrayNoMult10(int inputVals[], int numVals) {

for (int i = 0; i < numVals; i++) {

if (inputVals[i] % 10 == 0) {

return false;

}

}

return true;

}

int main() {

int size, input;

scanf("%d", &size);

int arr[size];

for (int i = 0; i < size; i++) {

scanf("%d", &input);

arr[i] = input;

}

if (IsArrayMult10(arr, size)) {

printf("all multiples of 10\\");

} else if (IsArrayNoMult10(arr, size)) {

printf("no multiples of 10\\");

} else {

printf("mixed values\\");

}

return 0;

}

Step-by-step explanation:

The program first defines two functions IsArrayMult10 and IsArrayNoMult10 which take an array of integers and the size of the array as parameters and return a boolean indicating whether the array contains all multiples of 10 or no multiples of 10, respectively.

In the main function, the program first reads the size of the list from standard input, then reads the list values one by one and stores them in an array. Finally, it calls the two functions to determine whether the list contains all multiples of 10, no multiples of 10, or mixed values, and prints the appropriate output.

User Vedat
by
7.4k points