C program to display sum of first 10 even numbers using for loop

 

C program to display sum of first 10 even numbers using for loop


/**************************************************

 C program to display sum of first 10 even numbers using for loop

 **************************************************/

 #include<stdio.h>

#include<conio.h>

 void main()

 {

     int sum=0;

    clrscr();

     printf("** OUTPUT**\n");

     printf("First 10 even numbers are\n");

     for(int i=1;i<=10;i++)

     {

         if(i%2==0)

         {

            printf("%d\n",i);

     

                sum=sum+i;

         }

     

     }

     printf("The sum of first 10 even numbers is: %d\n",sum);

     printf("End of program");

 }


** OUTPUT**

First 10 even numbers are

2

4

6

8

10

The sum of first 10 even numbers is: 30

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या