algoritm for sum of first 20 even numbers
Answers
Answered by
0
Answer:
#include<stdio.h>
void main()
{
int n,sum=0,i;
scanf("%d",&n);
for(i=1;i<=n;i++)
if(i%2==0)
sum = sum+i;
printf("%d",sum);
}
Explanation:
Algorithm
1) First Take input n from user if user gives input as 20.
2) Use for loop to check the number from 1 to user number n.
3) % operator will give you the even numbers if remainder is 0.
4)we will store the value of i in variable sum and will add till the for loop doesn't end at 20.
5)print the sum at last.
Similar questions