C programming 1- question 2- is my code what I want is to edit my code so it can
ID: 2267648 • Letter: C
Question
C programming
1- question
2- is my code
what I want is to edit my code so it can be compiled
Problem A: Write a function that has one integer parameter and returns 1 if the given argument is a multiple of 3 and 0 otherwise. Write a main program that tests your function with enough test cases to give you confidence in the correctness of your function. Use assertions and, optionally, calls to printf. The function prototype should be
int multipleof3(int n);
Hint: what does the % operator do?
Remember that the semicolon at the end of the prototype should not be copied in your solution. All code that you turn in should compile and run without errors or warnings to earn you full credit.
#include <assert.h>
#include <stdio.h>
//1 true 0 false
int multipleof3(int n){
int 3, int 16, int 18
multipleof3 =n/3
{
if(n%3==0)
return 1;
else if(n%3!=0)
return 0;
}
int main(){
int val=multipleof3(35);
assert(val==0);
return 0;
Explanation / Answer
#include <stdio.h>
#include <assert.h>
int multipleof3 (int n)
{
if ((n%3) == 0)
return 1;
else
return 0;
}
int main ()
{
int num1, val;
// Taking number of iterations start/end value of num1 can be set to anything
for (num1 = 2 ; num1 < 50; num1 = num1 + 2) {
assert (num1 > 0); // This assertion is kept such that if num1 has to be greater than 0
val = multipleof3(num1);
if (val == 1)
printf ("The number %d is a multiple of 3 ", num1);
else
printf ("The number %d is not a multiple of 3 ", num1);
}
return 0;
}
/******************* Output of Program ************************
The number 2 is not a multiple of 3
The number 4 is not a multiple of 3
The number 6 is a multiple of 3
The number 8 is not a multiple of 3
The number 10 is not a multiple of 3
The number 12 is a multiple of 3
The number 14 is not a multiple of 3
The number 16 is not a multiple of 3
The number 18 is a multiple of 3
The number 20 is not a multiple of 3
The number 22 is not a multiple of 3
The number 24 is a multiple of 3
The number 26 is not a multiple of 3
The number 28 is not a multiple of 3
The number 30 is a multiple of 3
The number 32 is not a multiple of 3
The number 34 is not a multiple of 3
The number 36 is a multiple of 3
The number 38 is not a multiple of 3
The number 40 is not a multiple of 3
The number 42 is a multiple of 3
The number 44 is not a multiple of 3
The number 46 is not a multiple of 3
The number 48 is a multiple of 3
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.