C program to display sum of first N even numbers using for loop
/************************************************************
C program to display sum of first n even numbers
***********************************************************/
#include<stdio.h>
void main()
{
int i,num,sum=0;
printf("** OUTPUT**\n");
printf("How many even number you wants to display\n");
scanf("%d",&num);
printf("First N even numbers are\n");
for(i=0;i<=num;i++)
{
if(i%2==0)
{
printf("%d\n",i);
sum=sum+i;
}
}
printf("The sum of first N even numbers is: %d\n",sum);
printf("End of program");
}
** OUTPUT**
How many even number you wants to display
35
First N even numbers are
0
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
The sum of first N even numbers is: 306
End of program
0 टिप्पण्या
कृपया तुमच्या प्रियजनांना लेख शेअर करा आणि तुमचा अभिप्राय जरूर नोंदवा. 🙏 🙏