Write a program to check and display all even number between 1 to20 using foor loop
Answers
Answered by
0
Explanation:
#include<stdio.h>
int main()
{
int num, count = 1, sum = 0;
printf("Enter the limit\n");
scanf("%d", &num);
while(count <= num)
{
if(count%2 == 0)
{
sum = sum + count;
}
count++;
}
printf("Sum of Even numbers from 1 to %d is %d\n", num, sum);
return 0;
}
Output 1:
Enter the limit
5
Sum of Even numbers from 1 to 5 is 6
Output 2:
Enter the limit
20
Sum of Even numbers from 1 to 20 is 110
Similar questions
Social Sciences,
12 days ago
Math,
12 days ago
Geography,
25 days ago
Math,
8 months ago
Math,
8 months ago