Write a C++ program to check if a given non-negative given number is a multiple of 3 or 7, but not both

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to check if a given non-negative given number is a multiple of 3 or 7, but not both

Sample Output:

1
1
0

الأجوبة

#include <iostream>
 
using namespace std;

bool test(int n)
        {
            return n % 3 == 0 ^ n % 7 == 0;
        }
     
        
int main() 
 {
  cout << test(3) << endl; 
  cout << test(7) << endl; 
  cout << test(21) << endl;         
  return 0;      
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...