1) Check Leap Year
#include <iostream>
using namespace std;
int main() {
int year = 2024;
if((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
cout << "Leap Year";
else
cout << "Not Leap Year";
return 0;
}
Output: Leap Year
2) Print Natural Numbers (1–N)
#include <iostream>
using namespace std;
int main() {
int n = 5;
for(int i = 1; i <= n; i++)
cout << i << " ";
return 0;
}
Output: 1 2 3 4 5
3) Print Sum of N Natural Numbers
#include <iostream>
using namespace std;
int main() {
int n = 5, sum = 0;
for(int i = 1; i <= n; i++)
sum += i;
cout << "Sum = " << sum;
return 0;
}
Output: Sum = 15
4) Print Pattern (Star Triangle)
#include <iostream>
using namespace std;
int main() {
int n = 5;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= i; j++)
cout << "* ";
cout << "\n";
}
return 0;
}
Output: * * * * * * * * * * * * * * *
5) Print Squares of Numbers (1–N)
#include <iostream>
using namespace std;
int main() {
int n = 5;
for(int i = 1; i <= n; i++)
cout << i << "^2 = " << i*i << "\n";
return 0;
}
Output: 1^2 = 1 2^2 = 4 3^2 = 9 4^2 = 16 5^2 = 25