print all even numbers before 100
Answers
Answered by
0
#include <stdio.h>
int main() {
int counter;
printf("Even numbers between 1 to 100\n");
/*
* Initialize counter with 1, and increment it in every iteration.
* For every value of counter check whether it is even number or
* not and print it accordingly
*/
for(counter = 1; counter <= 100; counter++) {
/* Even numbers are divisible by 2 */
if(counter%2 == 0) {
/* counter is even, print it */
printf("%d ", counter);
}
}
return 0;
}
int main() {
int counter;
printf("Even numbers between 1 to 100\n");
/*
* Initialize counter with 1, and increment it in every iteration.
* For every value of counter check whether it is even number or
* not and print it accordingly
*/
for(counter = 1; counter <= 100; counter++) {
/* Even numbers are divisible by 2 */
if(counter%2 == 0) {
/* counter is even, print it */
printf("%d ", counter);
}
}
return 0;
}
Answered by
0
/**
* C program to print all even numbers from 1 to n
*/
#include <stdio.h>
int main()
{
int i, n;
/* Input upper limit of even number from user */
printf("Print all even numbers till: ");
scanf("%d", &n);
printf("Even numbers from 1 to %d are: \n", n);
/*
* Start loop counter from 1, increment it by 1,
* will iterate till n
*/
for(i=1; i<=n; i++)
{
/* Check even condition before printing */
if(i%2 == 0)
{
printf("%d\n", i);
}
}
return 0;
}
Logic to print even
Similar questions