Algorithm
Even Square
Adapted by Neilor Tonin, URI Brazil
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 |
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
Output
#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
Output
#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
Output
#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
Output