Output needed for calculating sum of even arrays using C Programming

Asked By 120 points N/A Posted on -
qa-featured

Hi,

I need a program that will calculate the sum of even numbers in an array. My assignment is to develop a program that will show the output of the sum of even no’s in an array. Can anyone help me on this please?

SHARE
Best Answer by MarkJason
Answered By 0 points N/A #88384

Output needed for calculating sum of even arrays using C Programming

qa-featured

N1=5;

N2=9;

N3=2;

N4=1;

N5=2;

N6=1;

N7=3;

N8=5;

N9=8;

N10=6;

Int sum=0;

For(i=0;i<=9;i++)

{

if(n1to10%2==0)

sum=sum+n(1-10)

 }

cout<<sum

Answered By 120 points N/A #88385

Output needed for calculating sum of even arrays using C Programming

qa-featured

No Dear,

The program will take 10 inputs from the user that will be stored in an array. Here you are not using an array. Please give me a concept of an array to do this work. How can I take input from the user and how will it be saved in an array?

Answered By 0 points N/A #88386

Output needed for calculating sum of even arrays using C Programming

qa-featured

You will take the input in the array as you take input in a single variable. For example cin>>a; is taking input from user and saving that input value in a. Here you will use for loop for taking input of 10 values from user and save it in array as follows:

For(i=0;i<=9;i++)

{

Cout<<”Enter “<<i<<” Value in array”<<endl;

Cin>>arr[i];

}

Best Answer
Best Answer
Answered By 0 points N/A #88387

Output needed for calculating sum of even arrays using C Programming

qa-featured

Complete solution of this problem is as follows. Here I am not going to define you the details, you need to read your notes to clear the concepts. If you need more help then I am here for you dear.

#include<iostream.h>

#include<conio.h>

void main()

{

int arr[i];

int I,sum=0;

clrscr();

For(i=0;i<=9;i++)

{

Cout<<”Enter “<<i<<” Value in array”<<endl;

Cin>>arr[i];

If(arr[i]%2==0)

Sum=sum+arr[i];

}

cout<<”Sum of even Numbers is = “<<sum<<endl;

getch();

}

Answered By 120 points N/A #88388

Output needed for calculating sum of even arrays using C Programming

qa-featured

I am going to be a fan of your programming. Let me thank you especially for your help – no doubt you are a good programmer. One more thing, please: what will be the change in working if I want to calculate the sum of odd numbers instead of even numbers?

Once again, Thanks a lot sir.

Answered By 0 points N/A #88389

Output needed for calculating sum of even arrays using C Programming

qa-featured

I must say thumbs up to you Mark Jason; Superb.

Answered By 0 points N/A #88390

Output needed for calculating sum of even arrays using C Programming

qa-featured

There will only be one change; that is: If(arr[i]%2!=0) instead of If(arr[i]%2==0).

Answered By 0 points N/A #88391

Output needed for calculating sum of even arrays using C Programming

qa-featured

Hey,

The above Mark's code won't even compile. Check this out

First and foremost, you cannot declare an array like this –

int arr[i];
prog.cpp:5: error: ‘i’ was not declared in this scope

You have to initialize i to declare it in that way.

Second,

Sum=sum+arr[i];
prog.cpp:15: error: ‘Sum’ was not declared in this scope

You cannot use Sum when you have initialized

int sum = 0;

It becomes a different variable, and you cannot use it.

These are some of the basic programming errors that any coder can identify.

There are few more errors, but I'll leave it to you.

Regards,

Sanders Danny

Login/Register to Answer

Related Questions