w3resource
C Programming Exercises

C Exercises: Check if a given positive number is a multiple of 3 or a multiple of 7

C-programming basic algorithm: Exercise-5 with Solution

Write a C program to check if a given positive number is a multiple of 3 or a multiple of 7.

C Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
    printf("%d",test(3));
    printf("\n%d",test(14));
    printf("\n%d",test(12));
    printf("\n%d",test(37));
    }   
   int test(int n)
        {
            return n % 3 == 0 || n % 7 == 0;
        }

Sample Output:

1
1
1
0

Pictorial Presentation:

C Programming Algorithm: Check if a given positive number is a multiple of 3 or a multiple of 7

Flowchart:

C Programming Algorithm Flowchart: Check if a given positive number is a multiple of 3 or a multiple of 7

Solution

Contribute your code and comments through Disqus.

Previous: Write a C program to check a given integer and return true if it is within 10 of 100 or 200.
Next: Write a C program to check if one given temperatures is less than 0 and the other is greater than 100.