Program that checks if a given non-negative number is a multiple of 3 or 7, but not both.

Here, we have a basic program example to check if a number is multiple of 3 or 7 using different languages. This program is created in c language, c++, Java, and Python.

Program to check if a number is multiple of 3 or 7 in C language

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int num;
    printf("enter a number: ");
    scanf("%d",&num);

    printf("\n%d",test(num));
    }

    int test(int n)
         {
            return n % 3 == 0 ^ n % 7 == 0;
        }

Program to check if a number is multiple of 3 or 7 in C++ language

#include <iostream>
using namespace std;
bool test(int n)
        {
            return n % 3 == 0 ^ n % 7 == 0;
        }
int main()
 {
  int num;
  cout << "enter a number: " << endl;
  cin>>num;
  cout << test(num) << endl;
  return 0;
}

Program to check if a number is multiple of 3 or 7 in Python language

num=int(input("enter a number : "))
if num % 3 ==0 ^ num % 7 == 0:
    print("true")
else:
    print("false")

Program to check if a number is multiple of 3 or 7 in Java language

import java.util.Scanner;
class test{
  public static void main(String[] args)
    {
       int num;
       Scanner sc = new Scanner(System.in);
       System.out.print("Enter the number:  ");
       num=sc.nextInt();
   if (num % 3 ==0 ^ num % 7 == 0){
              System.out.println("true");
           }
   else{
             System.out.println("false");
            }

}
}