Please help me"Printing Elements of Array"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "stdafx.h"
#include <iostream>

    using namespace std;

    const unsigned int ARRAY_SIZE = 50;
//  ==========================
    void PrintArray(double&, double);

//  ============
    int main() {
        double Alpha[ARRAY_SIZE];
        int ii;
        

        Alpha[0] = 0;
        Alpha[1] = 1;
        Alpha[2] = 2;
        Alpha[3] = 3;
        Alpha[4] = 4;
        Alpha[5] = 5;
        Alpha[6] = 6;
        Alpha[7] = 7;
        Alpha[8] = 8;
        Alpha[9] = 9;
        Alpha[10] = 10;
        Alpha[11] = 11;
        Alpha[12] = 12;
        Alpha[13] = 13;
        Alpha[14] = 14;
        Alpha[15] = 15;
        Alpha[16] = 16;
        Alpha[17] = 17;
        Alpha[18] = 18;
        Alpha[19] = 19;
        Alpha[20] = 20;
        Alpha[21] = 21;
        Alpha[22] = 22;
        Alpha[23] = 23;
        Alpha[24] = 24;
        Alpha[25] = 25;
        Alpha[26] = 26;
        Alpha[27] = 27;
        Alpha[28] = 28;
        Alpha[29] = 29;
        Alpha[30] = 30;
        Alpha[31] = 31;
        Alpha[32] = 32;
        Alpha[33] = 33;
        Alpha[34] = 34;
        Alpha[35] = 35;
        Alpha[36] = 36;
        Alpha[37] = 37;
        Alpha[38] = 38;
        Alpha[39] = 39;
        Alpha[40] = 40;
        Alpha[41] = 41;
        Alpha[42] = 42;
        Alpha[43] = 43;
        Alpha[44] = 44;
        Alpha[45] = 45;
        Alpha[46] = 46;
        Alpha[47] = 47;
        Alpha[48] = 48;
        Alpha[49] = 49;
        
        ii = 0;
        while ( ii < 0 ){
            if ( ii <= ARRAY_SIZE/2 )
                Alpha[ii] = ii*ii;
            else 
                Alpha[ii] = 3*ii;
            ii++;
        }
        
         PrintArray(Alpha[ii],10);
    
        
        return 0;

    } // Function Main
//  ==================
    void PrintArray(double& , double length) {
        double Alpha[10];

        Alpha[0] = 0;
        Alpha[1] = 1;
        Alpha[2] = 2;
        Alpha[3] = 3;
        Alpha[4] = 4;
        Alpha[5] = 5;
        Alpha[6] = 6;
        Alpha[7] = 7;
        Alpha[8] = 8;
        Alpha[9] = 9;

        int ii;
        
        double c;
        for ( ii = 0; ii <length; ii++) {
            c =  Alpha[ii]*ii ;
            cout <<  c << endl;

        
        }}




The output is:
0
1
4
9
16
25
36
49
64
81
Press any key to continue . . .

I would like to Output into a row instead of a line.
Please help me this. :(:(:(
cout << c << endl;

instead write
cout<<c<<"\t';

endl causes output to ge next line
put single quotes '/t'
I mean they are separated by space not '\t' <- tab.

:(:(
May I offer a suggestion about how you initialize your array? Instead of writing 50 lines of code to initialize your array, use a loop.

1
2
3
4
for (int i = 0; i < ARRAY_SIZE; i++)
{
   Alpha[i] = i;
}
Last edited on
@Twistermonkey: Thank you!!! IT saves me lots of time.
Topic archived. No new replies allowed.