ATTENTION!!!: This assignment is for a basic and introductory C++ course. As suc
ID: 3836524 • Letter: A
Question
ATTENTION!!!: This assignment is for a basic and introductory C++ course. As such, please do not use complex or obscure opperations and headers that would typically be used in advanced classes as we have not learned them yet. Use only very simple functions and headers. If you are unsure of whether a technique is too advanced, dont use it. If you can answer the question without using a function, please do so.
"C type" string is implied to mean an array of characters with an end of string mark following the last character.
Write a function Named Divisors with four integer arguments. The function will return an integer based on the following conditions: If the first argument is a multiple of the second, the value is 1. If the first argument is a multiple of the third argument, the value is 10. If the first argument is a multiple of the fourth, the value is 100. If the first argument is a multiple of more than one of the other arguments, add the corresponding return values together. If the first argument is not a multiple of any other argument, return 0.
Explanation / Answer
#include <iostream>
#include <cstring>
using namespace std;
int Divisors (int a, int b, int c, int d){
int result = 0;
if(a % b == 0){
result+=1;
}
if(a % c == 0){
result+=10;
}
if(a % d == 0){
result+=100;
}
return result;
}
int main()
{
int a = 50, b = 5, c = 22, d = 10;
cout<<Divisors(a,b,c,d)<<endl;
return 0;
}
Output:
sh-4.2$ g++ -std=c++11 -o main *.cpp
sh-4.2$ main
101
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.