| | |
C++ with Arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
// try out
//Program - 5.4
# include <iostream.h>
# include <conio.h>
void main ( )
{
int x[5] = {1,2,3,4,5}, y [5] = {5,4,3,2,1},
result [5] = { 0,0,0,0,0 };
int i= 0;
while (i++ < 5)
result [i] = x [i] - y [i];
clrscr ( );
cout << “\n The contents of the array are: \n”;
i= 0 ;
do
{
cout << ‘\t’ << x [i]
<< ‘\t’ << y [i]
<< ‘\t’ << result [i]<<‘\n’;
i++;
} while (i<5);
getch ( );
}
What is the output of the below program?
I want walk through of this program
//Program - 5.4
# include <iostream.h>
# include <conio.h>
void main ( )
{
int x[5] = {1,2,3,4,5}, y [5] = {5,4,3,2,1},
result [5] = { 0,0,0,0,0 };
int i= 0;
while (i++ < 5)
result [i] = x [i] - y [i];
clrscr ( );
cout << “\n The contents of the array are: \n”;
i= 0 ;
do
{
cout << ‘\t’ << x [i]
<< ‘\t’ << y [i]
<< ‘\t’ << result [i]<<‘\n’;
i++;
} while (i<5);
getch ( );
}
What is the output of the below program?
I want walk through of this program
C++ Syntax (Toggle Plain Text)
// try out //Program - 5.4 # include <iostream.h> # include <conio.h> void main ( ) { int x[5] = {1,2,3,4,5}, y [5] = {5,4,3,2,1}, result [5] = { 0,0,0,0,0 }; int i= 0; while (i++ < 5) result [i] = x [i] - y [i]; clrscr ( ); cout << “\n The contents of the array are: \n”; i= 0 ; do { cout << ‘\t’ << x [i] << ‘\t’ << y [i] << ‘\t’ << result [i]<<‘\n’; i++; } while (i<5); getch ( ); } What is the output of the below program? I want walk through of this program
0
#2 Oct 21st, 2009
c++ Syntax (Toggle Plain Text)
int x[5] = {1,2,3,4,5}, y[5] = {5,4,3,2,1}, result[5] = {0,0,0,0,0};
This creates 3 arrays of the type int, with the names x, y and result.
c++ Syntax (Toggle Plain Text)
int i = 0; while(i++ < 5) result[i] = x[i] - y[i];
This loops through a range of 1 to 5 with i as the current value, and puts x[i] - y[i] into result[i]
c++ Syntax (Toggle Plain Text)
clrscr();
c++ Syntax (Toggle Plain Text)
cout << “\n The contents of the array are: \n”; i= 0 ; do { cout << ‘\t’ << x [i] << ‘\t’ << y [i] << ‘\t’ << result [i]<<‘\n’; i++; } while (i<5);
'\n' = newline
'\t' a tab(usually equal to the width of 4 spaces)
this prints out all the contents of the arrays, one after eachother while i(which gets incremented(+1) each run through the loop) is smaller then 5.
c++ Syntax (Toggle Plain Text)
getch();
If anyone see's something incorrect, or they think they can offer a better explanation, feel free to correct me.
...
0
#3 Oct 21st, 2009
Alternatively, you could visit this:
http://www.cplusplus.com/doc/tutorial/
And look at the things in there like loops, arrays, variables and stuff that you are curious about
http://www.cplusplus.com/doc/tutorial/
And look at the things in there like loops, arrays, variables and stuff that you are curious about
Last edited by tomtetlaw; Oct 21st, 2009 at 7:12 am.
...
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Insert Problem in Using a MySQL Database with C++
- Next Thread: Ms-Access as back end for files in cpp
Views: 200 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





