Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Generate an even squares between 1 to n using for loop in C Programming
Even square numbers are - 22, 42, 62, 82,………
= 4, 16, 36, 64, 100, ………
Algorithm
START Step 1: declare two variables a and n Step 2: read number n at runtime Step 3: use for loop to print square numbers For a=2; a*a<=n;a+=2 until the condition satisfy loop will continue and Print a*a STOP
Program 1
#include<stdio.h>
int main(){
int a,n;
printf("enter a number for n:");
scanf("%d",&n);
for(a=2;a*a<=n;a+=2) //print even squares that are present in between 1 and n{
printf("%d
",a*a);
}
return 0;
}
Output
enter a number for n:200 4 16 36 64 100 144 196
Program 2
Following is the program to find even cubes between 1 to n −
#include<stdio.h>
int main(){
int a,n;
printf("enter a number for n:");
scanf("%d",&n);
for(a=2;a*a*a<=n;a+=2){
printf("%d
",a*a*a);
}
return 0;
}
Output
enter a number for n:300 8 64 216
Advertisements
