Algorithm


Problem Name: beecrowd | 1073
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1073

Even Square

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

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

Input

The input contains 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.

Be carefull! Some language automaticly print 1e+006 instead 1000000. Please configure your program to print the correct format setting the output precision.

Input Sample Output Sample

6

2^2 = 4
4^2 = 16
6^2 = 36

Code Examples

#1 Code Example with C Programming

Code - C Programming


#include <stdio.h>
int main()
{
    int n, i;

    scanf("%d", &n);

    for ( i = 1; i  < = n; ++i)
    {
        if(i % 2 == 0){
            printf("%d^2 = %dn", i,(i * i));
        }
    }

 return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
2^2 = 4 4^2 = 16 6^2 = 36

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
using namespace std;
 
int main(int argc, const char * argv[])
{
    int N, i;
    
    cin >> N;

    for(i = 1; i  < = N; i++) {
        if(i%2 == 0) {
            cout << i << "^2 = " << i*i << endl;
        }
    }
 
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
2^2 = 4 4^2 = 16 6^2 = 36

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;
import java.io.IOException;

public class Main {

    public static void main(String[] args) {        
        int N;
        Scanner input =new Scanner(System.in);
        N =input.nextInt();
           
        for (int i = 2; i  < = N; i+= 2) {
            System.out.print(i+"^2 = "+(i*i)+"n");
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
2^2 = 4 4^2 = 16 6^2 = 36

#4 Code Example with Python Programming

Code - Python Programming


a=int(input())
for n in range(1,(a+1)):
    if (n%2==0):
        print("%d^2 = %d" %(n, n**2))
Copy The Code & Try With Live Editor

Input

x
+
cmd
6

Output

x
+
cmd
2^2 = 4 4^2 = 16 6^2 = 36
Advertisements

Demonstration


Previous
#1072 Beecrowd Online Judge Solution 1072 Interval 2 - Solution in C, C++, Java, Python and C#
Next
#1074 Beecrowd Online Judge Solution 1074 Even or Odd - Solution in C, C++, Java, Python and C#