C Program to Find Total of Even Integers

C Program to Find Total of Even Integers

The following C Program to Find Total of Even Integers and display them in ascending alphabetical order.

An array is a collection of variables of the same type. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows :-

type arrayName [ arraySize ];

An element is accessed by indexing the array name. This is done by placing the index of the element within square brackets after the name of the array.

For example :-

double salary = balance[9];

Save program in a file, Compile C program, debug errors, Execute or Run program with necessary inputs. Verify the outputs obtained.

Example 1 : C Program to Find Total of Even Integers

/*Program to find total of even integers*/
#include<stdio.h>
main()
{
int a[20],i,sum=0;
printf("enter5 integers");
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(i=0;i<5;i++)
{
if(a[i]%2==0)
sum=sum+a[i];
}
prinf("sum =%d",sum);
getch();
}

Output

Entger 5 integers
2 4 7 8 2
Sum = 16

Example 2: Find Total of Even Integers using while loop

#include<stdio.h>

int main()
{
      int count = 1, limit, sum = 0;
      printf("\nEnter Limit:\t");
      scanf("%d", &limit);
      while(count <= limit)
      {
            if(count%2 == 0)
            {
                  sum = sum + count;
            }
            count++;
      }
      printf("\nSum of Even Numbers from 1 To %d:\t %d", limit, sum);
      printf("\n");
      return 0;
}

Let me know if you find any difficulty in understanding this C Program to Find Total of Even Integers example and I would be glad to explain it further.

Online Training Tutorials