Saturday, May 22, 2010

Please help me in my turbo c program?

a multiplication table using for loops..

Please help me in my turbo c program?
Hi,


Suppose u want to generate multiplication table from 2 to 20,





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





void main()


{


int i,j;


for(i=2;i%26lt;21;i++)


{


for(j=1;j%26lt;11;j++)


printf("%d*%d = %d\n",i,j,i*j);


printf("Next Table\n\n");


}


getch();


}
Reply:A problem with Joel's answer;


Use definition line:


int iMultiplier, iMultiplicand, iResult[100][100]; //No init needed


Change the statement following the last for loop to:


iResult[iMultiplier][iMultiplicand]=iM...


And eliminate all of the brackets in the for loops. As long as you have one statement following the last for, you don't need them.
Reply:int [100,100] iResult;


int iMultiplier, iMultiplicand;





for(iMultiplier=0; iMultiplier%26lt; 100; iMultiplier++); {


for(iMultiplicand=0; iMultiplicand%26lt; 100; iMultiplicand++); {


iResult[iMultiplier, iMultiplicand] = iMultiplier*iMultiplicand;


}


}

wallflower

No comments:

Post a Comment