| | |
arrays proplem
Thread Solved
![]() |
c++ Syntax (Toggle Plain Text)
for(int i=0 ; i<50 ; i++) {cout<<a[i]<<" "; if(i%10 == 0) cout<<endl; }
you had to use
cout<<endl if i is divisble by 10 i.e. 10 elements has been printed.. Last edited by rajatC; Dec 30th, 2007 at 5:19 am.
Life is about being happy...
it will print 11 elements in first line and 10 in all others...
to be more accurate use...
to be more accurate use...
c++ Syntax (Toggle Plain Text)
for(int i=1 ; i<51 ; i++) { cout<<setw(3)<<a[i-1]<<" "; if(i%10 == 0) cout<<endl; }
Life is about being happy...
•
•
•
•
c++ Syntax (Toggle Plain Text)
for(int i=0 ; i<50 ; i++) {cout<<a[i]<<" "; if(i%10 == 0) cout<<endl; }
you had to usecout<<endlif i is divisble by 10 i.e. 10 elements has been printed..
C++ Syntax (Toggle Plain Text)
if( (i+1)%10 == 0)
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
this is my answer ; is it right ?
C++ Syntax (Toggle Plain Text)
# include <iostream> #include <iomanip > using namespace std ; int main () { int alpha[50]; for (int i=0;i<25;i++) { alpha[i]=i*i; cout<<alpha[i]<<" "; } for(int i=25;i<50;i++) { alpha[i]=3*i; cout<<alpha[i]<<" "; } for(int i=1 ; i<51 ; i++) { { cout<<setw(3)<<alpha[i-1]<<" "; if( (i+1)%10 == 0) cout<<endl; } } return 0; }
there are always hope
This works if you don't mind the newline right from the get go.
cpp Syntax (Toggle Plain Text)
if (i % 10 == 0) cout << endl; cout << alpha[i] << "\t";
I'd guess that you should be able to determine if it's right or not and I'm suspecting you're guessing it's not.
I'd suggest removing the
I removed those cout statements and your code is nearly there. The first line only prints 9 numbers, the rest print 10.
I'd suggest removing the
cout statements from the for loops of the assignment statements, they just print 25 across the line, which is not what you want.I removed those cout statements and your code is nearly there. The first line only prints 9 numbers, the rest print 10.
for(int i=1 ; i<51 ; i++) { { cout<<setw(3)<<alpha[i-1]<<" "; if( (i+1)%10 == 0) cout<<endl; } }
There are 2 ways to choose to print 10 numbers for each line.
C++ Syntax (Toggle Plain Text)
for (int i=0; i<50; i++) { cout << alpha[i] << " "; if ((i+1) % 10 == 0) cout << endl; }
C++ Syntax (Toggle Plain Text)
for (int i=1; i<51; i++) { cout << alpha[i-1] << " "; if (i % 10 == 0) cout << endl; }
C++ Syntax (Toggle Plain Text)
for (int i=0; i<50; ) { cout << alpha[i] << " "; if (++i % 10 == 0) cout << endl; }
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: direct access to hdd
- Next Thread: how to choos a path
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets





