Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
who can i write a algorithm to the question
the question said:
To write a C++ program to read five integer 
elements into an array and find their sum 

please help me to write the algorithm

What I have tried:

Purpose : To write a C++ program to read five integer elements into an array and find their sum.
#include <iostream>
using namespace std;

int main()
    int A[5];
    int sum=0;
    cout<<"Enter the array elements :"<<endl;
 for(int i=0; i<5; i++)
  cin>> A[i];
    for(int i=0; i<5; i++)
        sum = sum + A[i];
    cout << "The sum of the elements is :" <<sum<<endl;
 return 0;
Updated 30-Jun-23 4:23am
CPallini 3-May-21 6:18am    
You don't need help. Your code, as it stands, compiles and runs fine.
AAisha Sultan Salim Al Kindi 3-May-21 7:33am    
yes i knew the code it is correct but i want the explain and algorithm of the code
CPallini 3-May-21 7:38am    
Nothing better then than you, the author of the code, can explain the implemented algorithm.
AAisha Sultan Salim Al Kindi 3-May-21 7:41am    
I don't understand the code to write the algorithm
CPallini 3-May-21 7:44am    
So it is not yours.
Start reading a tutorial on C++ (or C) loops and arrays. The code is simple, grasping it should be easy.

Your code compiles, runs and produces a correct answer: so what more is necessary?

If what you have isn't enough, you need to go back to your exact assignment, read it again very carefully, and work out what exactly it expects you to hand in.

We can't do that for you!
Share this answer
AAisha Sultan Salim Al Kindi 3-May-21 7:09am    
can you write an algorithm to the code I gave you
OriginalGriff 3-May-21 7:56am    
"Loop though all elements, adding them together"?
AAisha Sultan Salim Al Kindi 3-May-21 8:30am    
can you help me to write a code to this question
To write a C++ function which accepts your name
(string) as an input and print it in reverse order
without using a built in function.
OriginalGriff 3-May-21 8:50am    
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help:

But your attitude of "oh i don't have enough time to read ....." hasn't exactly enamoured you to people ...
AAisha Sultan Salim Al Kindi 3-May-21 13:28pm    
I am sorry for the misunderstanding. I understood that this website gives the answer for the student and not his help. I'm sorry I didn't intend that
#include <bits stdc++.h="">
using namespace std;
int main(){
int arr[5];int sum = 0;
for(int i = 0 ;i<5;i++){
sum+=arr[i]; //short and efficient code;
Share this answer
Dave Kreskowiak 30-Jun-23 11:06am    
Doing homework for someone is a really bad idea.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900