2 Replies - 17074 Views - Last Post: 10 April 2009 - 11:20 AM Rate Topic: -----

#1 daeskalade  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-April 07

Multiplication Table in C

Posted 26 April 2007 - 03:52 PM

Im trying to make a multiplication table in C. we have only learned for loops, while loops, and the basic stuff. when i run this program, it give me a table, but all the entries are the same. can someone help me?

#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", (m*n));
		   }
		}

return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Multiplication Table in C

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Multiplication Table in C

Posted 26 April 2007 - 05:41 PM

Modify your print statement to use the values from the variables i and j inside the your loops. The values for m and n are static and will not change.
printf("%4d", (i*j));

Was This Post Helpful? 0
  • +
  • -

#3 pqgarvis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-April 09

Re: Multiplication Table in C

Posted 10 April 2009 - 11:20 AM

In addition to that change add the following code right below your printf inside your loop. This makes the table display correctly
printf("\n");

This post has been edited by pqgarvis: 10 April 2009 - 11:21 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1