Click here to Skip to main content
14,926,224 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:

I WRITE THE CODE OF THE QUESTION
/****************************************************************************************************
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;
}
Posted
Updated 3-May-21 0:32am
v3
Comments
CPallini 3-May-21 6:18am
   
You don't need help. Your code, as it stands, compiles and runs fine.
   
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.
   
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.
   
oh i don't have enough time to read .....
CPallini 3-May-21 8:06am
   
I'm very sorry to hear that, but...
You really should.
   
thank you
   
i have one more question in conclusion of this example what should i write
   
can you help me to write a code of 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.
   
please help me i should submit the algorithm today
Richard MacCutchan 3-May-21 9:41am
   
Then you should hurry up and get it written. No one here is going to do it for you.
   
Thank you for To encourage me

1 solution

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!
   
Comments
   
can you write an algorithm to the code I gave you
OriginalGriff 3-May-21 7:56am
   
"Loop though all elements, adding them together"?
   
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:
https://www.codeproject.com/Articles/5282084/How-to-Write-Code-to-Solve-a-Problem-A-Beginners-G

But your attitude of "oh i don't have enough time to read ....." hasn't exactly enamoured you to people ...
   
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
OriginalGriff 3-May-21 15:31pm
   
No, we do not do your homework for you - we will help those who have tried and are stuck, but homework is there for a reason: to help you to build a skill, and a way of thinking. You don't get any of that from handing in someone else's solution!
   
this is my 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."
and i should write the algorithm I tried to write, but I'm not sure if the answer is correct
The algorithm :
Step 1: Start

Step 2: Declare matrix A[r][c];
and matrix B[r][c];
and matrix C[r][c]; r= no. of rows, c= no. of columns

Step 3: Read r, c, A[][] and B[][]

Step 4: Declare variable i=0, j=0

Step 5: Repeat until i < r

5.1: Repeat until j < c

C[i][j]=A[i][j] + B[i][j]

Set j=j+1

5.2: Set i=i+1

Step 6: C is the required matrix after addition

Step 7: Stop
   
Mr see if my answer is correct if not let me know please. I again i say sorry . because i don't know how i write the message carefully . Thank you very much for help student
   
I have one question is this website only for All material like math because I just joined this site todayز

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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