1 to 100 print even number only in c programming
Even Numbers from 1 to 100 in C Programming
This page demonstrates how to print even numbers from 1 to 100 using C programming. Below is the code example:
#include <stdio.h>
int main() {
int i;
for (i = 2; i <= 100; i += 2) {
printf("%d\\n", i);
}
return 0;
}
Explanation
The provided C code snippet is used to print even numbers from 1 to 100. Here's a brief explanation of the code:
#include <stdio.h>: This line includes the standard input-output header file, which is necessary for using theprintffunction.int main(): This defines the main function where the execution of the program begins.int i;: This declares an integer variableithat will be used in the loop.for (i = 2; i <= 100; i += 2): This is a for loop that starts withiset to 2 (the first even number) and incrementsiby 2 until it reaches 100.printf("%d\\n", i);: This line prints the value ofifollowed by a newline character, resulting in each even number appearing on a new line.return 0;: This statement ends the program and returns 0, indicating that the program finished successfully.
Comments
Post a Comment