Thread: Multiplication program

  1. #1
    Registered User
    Join Date
    Mar 2015
    Posts
    3

    Multiplication program

    Can anyone help please trying to understand how to make a multiplication table upto 12 using c programing cant seem to get a program to run this if anyone can help please.

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Of course we can help. Why don't you start reading here and then perhaps take a look at the the homework policy and then you could even read up on how to ask questions. That should provide you with all the help you need. Oh and to help you going with getting a program to run:
    Code:
    int main(void)
    {
         return(0);
    }
    That runs fine for me.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Mar 2015
    Posts
    3
    im 46 year i dont need my homework done just need help as i am teaching myself

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Regardless, you still need to post your actual effort to date, so we can best guide you though the next step, and correct whatever mis-understandings you may have so far.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Mar 2015
    Posts
    3
    I have completed my for task to do my for loop table how do i now change this to while loop please.
    Code:
    int
    main (void){
      int i, j;
      i = 1;
      j = 1;
    
    
      printf ("   |");
      for (i = 1; i < 13; ++i)
      printf ("%3d   ",i);
      printf ("\n");
    
    
      for (i = 1; i < 75; ++i)
        printf ("-");
      printf ("\n");
    
    
      for (i = 1; i < 13; ++i){
          printf ("%2d |", i);
          for (j = 1; j < 13; ++j)
             printf ("%3d   ",i * j);
          	printf ("\n");
      }
      return 0;
    }

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by http://www.cprogramming.com/tutorial/c/lesson3.html
    WHILE - WHILE loops are very simple. The basic structure is
    Code:
     while ( condition ) { Code to execute while the condition is true }
    The true represents a boolean expression which could be x == 1 or while ( x != 7 ) (x does not equal 7). It can be any combination of boolean statements that are legal. Even, (while x ==5 || v == 7) which says execute the code while x equals five or while v equals 7. Notice that a while loop is like a stripped-down version of a for loop-- it has no initialization or update section.
    So to rework your the first part of your code:
    Code:
    int main(void)
    {
    
    	int i, j;
    	i = 1;
    	j = 1;
    
    
    	printf("   |");
    	
    	//for (i = 1; i < 13; ++i)
    	while (i < 13)
    	{
    		printf("%3d   ", i);
    		++i;
    	}
    	printf("\n");
    ///rest of program
    Additionally, since you had already initialized i, you could have rewritten your for loop like:
    Code:
    for (i; i < 13; ++i)
    However, since it is often best practice to declare variables with the most limited scope possible, let's rewrite your initial program:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    	
    	printf("   |");
    	
    	for (int i = 1; i < 13; ++i)
    	{
    		printf("%3d   ", i);
    		
    	}
    	printf("\n");
    
    
    	for (int i = 1; i < 75; ++i)
    	{
    		printf("-");
    	}
    	printf("\n");
    
    
    	for (int i = 1; i < 13; ++i)
    	{
    		printf("%2d |", i);
    		for (int j = 1; j < 13; ++j)
    		{
    			printf("%3d   ", i * j);
    		}
    		printf("\n");
    	}
    
    	return 0;
    }
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    Code:
    for ( init ; condition ; step ) {
    	  body;
    	}
    is logically equivalent to this (excepting the action of the continue keyword)
    Code:
    	init;
    	while( condition ) {
    	  body;
    	  step;
    	}
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c-program on multiplication of matrices using functions
    By dishagarg in forum C Programming
    Replies: 4
    Last Post: 02-28-2013, 11:14 AM
  2. Polynomial Multiplication program
    By daggerhunt in forum C Programming
    Replies: 2
    Last Post: 11-02-2012, 07:57 AM
  3. Multiplication Table Program
    By jamesallen4u in forum C Programming
    Replies: 3
    Last Post: 10-17-2011, 07:48 AM
  4. multiplication program
    By wankel in forum C Programming
    Replies: 11
    Last Post: 06-13-2009, 12:33 PM
  5. C program 2D matrix multiplication using malloc
    By college_kid in forum C Programming
    Replies: 5
    Last Post: 04-03-2009, 10:04 AM