Can anyone know what program what's the best for this problem?

-->Create a program that will compute for the sum of all even numbers among the ten integers inputted and print them out.


Thanks in advance!:)

Dani AI

Generated

Short answer: read ten integers in a loop, test each for evenness, add the evens to a running total, then print the total. 's starter main and 's suggestion to use a loop are exactly the right direction; 's example shows the even check but used a hard‑coded array instead of reading input. The snippet below is a compact, practical C solution that reads up to ten integers from standard input, skips invalid tokens, and prints the sum of even numbers.

#include <stdio.h>

int main(void)
{
    long long sum = 0;
    int n, read = 0;

    while (read < 10 && scanf("%d", &n) == 1) {
        if ((n & 1) == 0)  /* even test using bitwise */
            sum += n;
        read++;
    }

    if (read < 10)
        fprintf(stderr, "Warning: only %d value(s) read\n", read);

    printf("%lld\n", sum);
    return 0;
}

Notes and quick tips: zero is even (it will be included); negative even numbers count the same as positive evens. Using long long for the sum avoids overflow for typical inputs; if you expect extremely large values, use wider types or check for overflow. scanf is simple for homework; if you need to tolerate non-numeric garbage or want to read mixed tokens, use fgets + strtoll and handle parsing errors. Compile with gcc -std=c11 -Wall -Wextra to catch issues.

Recommended Answers

All 3 Replies

Homework? Here is where to start

#include <stdio.h>

int main()
{
   // put your code here
}

just make a loop for that!!!
its just a simple problem....you can do it just trust your intelegence

You can try this........I took the labor to not take input for my convinience

#include<stdio.h>
void main()
{
int n[]={1,2,3,4,5,6,7,8,9,10};
int i , total;
total=0;
for(i=0;i<10;i++)
 {
  if(n[i]%2==0)  //Checking for even numbers
   total = total + n[i];
 }
printf("%d",total);
}
commented: http://www.daniweb.com/software-development/c/threads/78060 -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.