Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

emacs24 vm-Tor-1310 + X File Edit Options BufTers Toals C Help -node : corpilation; default-directory: hn2ALsulainen Jehan/pbM" -+ nclude assert.h> tinclude stdso.h Conpilation started at Thu Feb 1 18:13:49 gcc -al -wextra -g utipleof3 multipleo3. Tultipleof3.c:error:expected identifier orbefure nuneric cons tant //1 true 0 Telse nt 3, int 10, int 1 int 3, int 1, int 1B multi pleo f3 =n/3 multipleof3.c:17:5: warning ' is narnally a nan-static functian -Wainl int minr rcturn 1 else if n31-8) return 0; Itpleof3.c:23: 1: error: cxpected declaration or statement at cnd of input witipleo13 :5121 warning: unused paraneter 'n' -Wunused-paraneterj int nultipleotint nit int main int val-multipleot3(35) assert val ); return uitinleo13 C:23: arnina: control reaches end of non-void function I-Wreturn-type] Conpilation exited abnornally with code1 Thu Fes 1 18:13:49

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
*/