_g3o_ Posted April 26, 2009 Share Posted April 26, 2009 Hello! i want a help in c++. I have to reverse one table but on the output the empty fills have a random value. I have to assign an empty value but i dont know how. here is my code include <stdio.h>#include <iostream> #include <conio.h> using std::cin; void printRTable(char array[20][20], int n) { int x, i; printf ("Printing Reverse Table\n"); for (i=1;i<=n;i++) { for (x=n;x>=1;--x) { printf(" %d",array[x]); } printf("\n"); } } void printTable(char array[20][20], int n) { int x, i, temp; printf ("Printing table\n"); for (x=1;x<=n;x++) { for (i=1;i<=x;i++) { temp = i * x; array[x] = temp; printf(" %d",temp); } printf("\n"); } printf("\n"); printRTable(array,n); } int main() { int N, x, i; char array[20][20]; printf ("Please enter N:"); cin >> N; for (x=1;x<=20;x++) { for (i=1;i<=20;i++) { array[x] = '0'; } } printTable(array,N); printf ("Please press any key to exit\n"); getch(); return 0; } the output that i must have is this one and i have this one as output Link to comment Share on other sites More sharing options...
0 Lant Posted April 26, 2009 Share Posted April 26, 2009 First of all apart from cin its not very c++ like, use cout instead of printf and you wont have to do stuff like printf("%d", blah). The second thing is that in c++ arrays are zero indexed so your for loops should look like: for (int x = 0; x < 20; ++x) Finally, what would be even better than arrays would be to use a container (vector of vectors?) so you have access to reverse_iterator. Link to comment Share on other sites More sharing options...
0 _g3o_ Posted April 29, 2009 Author Share Posted April 29, 2009 i found the solution for(x=1;x<=n;x++) { for(i=n;i>0;i--){ //elexume an to i enai mikrotero kai iso apo to x kai //an isxi tote ta polaplasiazume alios afinume keno //otan teliosi to for tu i tote pame sto for tu x opu alazume grami //kai prosthetume +1 mexri to x na gini iso me to n if(i<=x) printf(" %2d",x*i); else printf(" "); } printf("\n"); } } Link to comment Share on other sites More sharing options...
0 see-seA Posted April 30, 2009 Share Posted April 30, 2009 i found the solution Pity you couldn't work it out for yourself. Link to comment Share on other sites More sharing options...
0 The Canadian Posted April 30, 2009 Share Posted April 30, 2009 Pity you couldn't work it out for yourself. And, do you have any proof that he/she didn't work it out..?! Link to comment Share on other sites More sharing options...
Question
_g3o_
Hello! i want a help in c++. I have to reverse one table but on the output the empty fills have a random value. I have to assign an empty value but i dont know how. here is my code
the output that i must have is this one
and i have this one as output
Link to comment
Share on other sites
4 answers to this question
Recommended Posts