Question #38871

Read an integer N. Print the square of each one ofthe even values from 2 to N including N if is the case.
Input
The input contain an integer N.
Output
Print the square of each one of the even valuesfrom two to N, as the given example.
Sample Input&
6
Sample Output
2^2 = 4
4^2 = 16
6^2 = 36
1

Expert's answer

2014-02-04T09:38:47-0500
#include <stdio.h>
int main() {
    int number = 0;
    do {
        printf("Please input the number. Please note : it should be bigger or equal
than 2\n");
        scanf("%d", &number);
        if (number < 2) {
            printf("Number should be bigger or equal than 2\n");
        }
    } while (number < 2);
    if (number % 2 != 0) {
        number -= 1;
    }
    for (int i = 2; i <= number; i += 2) {
        printf("%d^2 = %d\n", i, i*i);
    }
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS