
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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
- Related Articles
- C program to display all prime numbers between 1 to N using for loop
- How to separate even and odd numbers in an array by using for loop in C language?
- Sum of squares of the first n even numbers in C Program
- How to generate the first 100 even Numbers using C#?
- An Interesting Method to Generate Binary Numbers from 1 to n?
- Find the only repetitive element between 1 to n-1 using C++
- C Program for n-th even number
- C program to print four powers of numbers 1 to 9 using nested for loop
- Write a number array and using for loop add only even numbers in javascript?
- How to generate different random numbers in a loop in C++?
- Add minimum number to an array so that the sum becomes even in C programming
- Difference between for loop and while loop in Python
- How to generate an UnsupportedOperationException in Java?\n
- Loop Keyword in Rust Programming
- While loop in Lua Programming

Advertisements