C++ Basic Syntax Exercises – Nested Branching and Ternary Operations

1. P5711 [Deep Foundation 3. Example 3] Leap Year Determination

C++ Basic Syntax Exercises - Nested Branching and Ternary Operations

#include<iostream>using namespace std; int main(){ int n; cin >> n; if(n % 400 == 0 || (n % 100 != 0 && n % 4 == 0)){ cout << 1; } else { cout << 0; } return 0;}

2. B2042 Determine if a Number is Divisible by Both 3 and 5

C++ Basic Syntax Exercises - Nested Branching and Ternary Operations

#include<iostream> using namespace std; int main(){ int n; cin >> n; if(n % 3 == 0 && n % 5 == 0){ cout << "YES"; } else { cout << "NO"; } return 0;}

Leave a Comment