A program that prompts the user to enter a number n, then prints all even square between 1 and n.

PHOTO EMBED

Mon Oct 07 2024 23:58:22 GMT+0000 (Coordinated Universal Time)

Saved by @khadizasultana #c #loop

#include<stdio.h>
// Author- Khadiza Sultana
// Date- 10/8/2024
// printing all even squares from 1 to n
#include<math.h> // includin math.h library for the pow function. We can simply write i*i instead

int main() { 
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
    
    int i = 1;
    while(pow(i,2)<= n) // checking if i^2 is equal to n or not. If yes then the loop is stoped. If no then continue
    {
        int square = pow(i,2); // storing the squares of the numbers
        if(square % 2 == 0) // checking if the squares are even or not
        {
            printf("%d\n", square);
        }
        i++; // incrementing i
    }
    
    return 0;
}
content_copyCOPY

If a user enters 100, the program should print the following- 4 16 36 100