multiplication table

This is a discussion on multiplication table within the C Programming forums, part of the General Programming Boards category; I am writting a program that displays a multiplication table....but my output is a constant 144 144 144 etc.... I ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    49

    multiplication table

    I am writting a program that displays a multiplication table....but my output is a constant 144 144 144 etc....

    I cant find the error in my program.

    Code:
    #include <stdio.h>
    #include<stdlib.h>
    
    int multab(int, int);
    int main()
    {
    	int a,b;
    	int table[12][12];
    
    	FILE * outfile;
    
    	outfile = fopen ("Michael Kuck's Project 4.txt", "w");
    
    	printf("Michael Kuck's Project 4 \n\n");
    	fprintf(outfile, "Michael Kuck's Project 4 \n\n");
    
    		printf("					Multiplication Table \n\n");
    		fprintf(outfile, "					 Multiplication Table \n\n");
    
    	for (a =1; a=12; a++)
    	{
    		for (b=1; b=12;b++)
    		{
    			table [a][b] = multab(a,b);		// function call (multiplication)
    			printf("%5d", table [a][b]);
    			fprintf(outfile, "%5d", table [a][b]);
    		}
    		printf("\n\n");
    		fprintf(outfile, "\n\n");
    	}
    	printf("End of Project 4 \n\n");
    	fprintf(outfile, "End of Project 4\n\n");
    
    	fclose(outfile);
    	return 0;
    } //end of function main
    int multab(int a, int b) // recursive definition for multiplication function
    {
    	int result;
    
    	if (b==1)
    		result = a;
    	else
    		result = a + multab(a,b -1);
    	return(result);
    } //end of function multab
    thanks
    Code this

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Code:
    >	for (a =1; a=12; a++)
    >	{
    >		for (b=1; b=12;b++)
    You are setting a and b equal to 12 as your for-loop condition. Instead use:
    Code:
    	for (a =1; a<12; a++)
    	{
    		for (b=1; b<12;b++)

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    49
    duh! thanks swoopy!!
    Code this

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiplication table
    By freddyvorhees in forum C++ Programming
    Replies: 6
    Last Post: 08-02-2008, 12:09 PM
  2. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 06:06 PM
  3. C++ Multiplication Table Generator
    By Visual Develope in forum C++ Programming
    Replies: 4
    Last Post: 05-15-2002, 12:22 PM
  4. Multiplication Table Error
    By Okiesmokie in forum C++ Programming
    Replies: 3
    Last Post: 01-10-2002, 03:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21