[URI Online Judge] – 1073 – Even Square

Read an integer N. Print the square of each one of the even values from 1 to N including N if is the case.

Input

The input contain an integer N (5 < N < 2000).

Output

Print the square of each one of the even values from 1 to N, as the given example.

Sample Input Sample Output
6 2^2 = 4
4^2 = 16
6^2 = 36

Solution:

#include <iostream>
#include <cstdio>
int main(){
 int n, i;
 std::cin >> n;
 for (i = 1; i <= n; i++){
 if (i % 2 == 0)
 printf("%d^2 = %d\n", i, i * i);
 }
 return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s