Beecrowd 1073 Even Square Problems Solution in C++, C, and Python

Even Square

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

Input

The input contains an integer (5 < < 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 SampleOutput Sample
62^2 = 4
4^2 = 16
6^2 = 36
 

First, let’s take a closer look at the problem itself. The URI BeeCrowd Bee 1073 Even Square problem asks you to find all the even numbers between 1 and a given number, and then print each number and its square on a separate line. This is a fairly simple problem, but it does require some basic coding skills and knowledge of loops and conditionals.

To solve this problem in C, C++, or Python, you’ll need to use a loop to iterate over all the even numbers between 1 and the given number. Then, for each even number, you’ll need to calculate its square and print the result to the console. We’ll provide detailed code examples in each language below.

C Solution

#include <stdio.h>

int main() {

    int i,n,s=1;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i%2==0){
           s=i*i;
           printf("%d^2 = %d\n",i,s);
        }


    }

    return 0;
}

In this C solution, we use a for loop to iterate over all the even numbers between 2 and the given number. We start at 2 instead of 1 because we know that 1 is not an even number. We increment the loop variable i by 2 at each iteration, which ensures that we only visit even numbers. Inside the loop, we print out the square of the current number using the %d format specifier for integers.

C++ Solution

#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    for(int i = 2; i <= n; i += 2) {
        cout << i << "^2 = " << i*i << endl;
    }
    return 0;
}

In this C++ solution, we use a similar approach to the C solution, but we use cout and cin instead of printf and scanf. We also use the namespace keyword to avoid having to prefix cout and cin with std:: every time.

Python Solution

n = int(input())
for i in range(2, n+1, 2):
    print(f'{i}^2 = {i*i}')

In this Python solution, we use a for loop and the range function to iterate over all the even numbers between 2 and the given number. We use an f-string to print out the square of the current number.

Conclusion

In this guide, we’ve provided detailed solutions to the URI BeeCrowd Bee 1073 Even Square problem in C, C++, and Python. We’ve also discussed some basic coding concepts and provided code examples in each language. We believe that this guide is the best resource available for solving this particular problem, and we hope that it helps you in your coding journey. Thank you for choosing Codeshikhi, and happy coding!

Beecrowd All solution

1 thought on “Beecrowd 1073 Even Square Problems Solution”

Leave a Comment