multiplication table

using arrays ni need a multiplication table

Page 1 of 1

2 Replies - 4697 Views - Last Post: 17 April 2008 - 01:29 PM Rate Topic: -----

#1 ariyawansa  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-April 08

multiplication table

Post icon  Posted 16 April 2008 - 09:57 PM

#include <stdio.h>

int main(){

int m, n;
int i, j;

printf("\nThis program generates an m x n multiplication table.");
printf("\nEnter number of rows (m): ");
scanf("%d", &m);
printf("Enter number of columns (n): ");
scanf("%d", &n);

for(i = 1; i <= m; i++){
for(j = 1; j <= n; j++){
printf("%4d", (i*j));
}
}
system("PAUSE");
return 0;
}

Is This A Good Question/Topic? 0
  • +

Replies To: multiplication table

#2 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1430
  • View blog
  • Posts: 11,006
  • Joined: 06-February 08

Re: multiplication table

Posted 17 April 2008 - 04:24 AM

Not bad, there are only two things to point out:
  • The system(); function is in <iostream>, which is a standard C++ library. Better practise in C would be to #include <conio.h> and replace system(); with getch();
  • The other thing is that this program works, it's just that it all prints on the same line, correct? Try putting printf("\n"); JUST after your nested for loop, like so:
for(i = 1; i <= m; i++)
{
	for(j = 1; j <= n; j++)
		printf("%4d", (i*j));

	printf("\n");
}


Hope this helps :)

Oh, and welcome to </d.i.c>
Was This Post Helpful? 0
  • +
  • -

#3 محمداسد  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-April 08

Re: multiplication table

Posted 17 April 2008 - 01:29 PM

View Postgabehabe, on 17 Apr, 2008 - 04:24 AM, said:

Not bad, there are only two things to point out:
  • The system(); function is in <iostream>, which is a standard C++ library. Better practise in C would be to #include <conio.h> and replace system(); with getch();
  • The other thing is that this program works, it's just that it all prints on the same line, correct? Try putting printf("\n"); JUST after your nested for loop, like so:
for(i = 1; i <= m; i++)
{
	for(j = 1; j <= n; j++)
		printf("%4d", (i*j));

	printf("\n");
}


Hope this helps :)

Oh, and welcome to </d.i.c>



Great :^: !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1