write a program to print first 10 even numbers
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Explanation:
This program prints n even numbers(not just 10) :
#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("All even numbers from 1 to %d are: \n", n);
while(i<=n)
{
/* Check even condition before printing */
if(i%2==0)
{
printf("%d\n", i);
}
i++;
}
return 0;
}
Verified answer
Answer:
start, end = 0, 10
for num in range(start, end + 1):
if num % 2 == 0:
print(num, end = " ")