Program to show a multiplication table

This is a discussion on Program to show a multiplication table within the C Programming forums, part of the General Programming Boards category; This program crashes. It allows me to enter a number that I want to multiply but then it just crashes ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    81

    Program to show a multiplication table

    This program crashes. It allows me to enter a number that I want to multiply but then it just crashes instead of doing the multiplication.

    Code:
    #include <stdio.h>
    
    
    int main()
    {
        int sum, num1, count; /*Variable to hold count*/
        count=1; /*Count set to 0*/
        printf("Enter the number you wish to multiply:\n");
        scanf("%d" ,num1);
        
        while (count < 13) /*While count is less than 5 program loops*/
        {
        sum = num1*count;
        printf("Multiplying %d by %d is %d\n", num1, count, sum); /*Prints sum*/ 
        count = count+1; /*count adds one*/
       } /*End of while loop*/
        
        return 0; /*Exits the program*/
    }

  2. #2
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    scanf is not working this way. Read more here.
    scanf differs from printf. Provide as argument a pointer to your variable (in reality address space). In you case &num1.

    scanf("%d", &num1);

    If you don't understand how this works then try to write a function that swaps the content of two numbers. Else read more about pointers.
    Last edited by ch4; 10-19-2011 at 10:48 AM.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    81
    If I was next to you I'd give you a hug! I was trying to work it out for ages!

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Interista View Post
    If I was next to you I'd give you a hug! I was trying to work it out for ages!
    In all those ages, did it ever once occur to you to look up the descriptions for the functions in your program to see what the proper syntax is?

    Even if your compiler doesn't have help files for it's library, all this stuff is out there...

    Like.... THIS

    And no, I'm not just being rude...
    Checking function syntax is a routine task for every programmer. We do this dozens, sometimes hundreds of times a day.
    There's no way you can remember all of it (there are hundreds of functions in the standard lbrary alone) so you either get
    the help files for your compiler's library or you spend time bookmarking helpful sites...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiplication Table Program
    By jamesallen4u in forum C Programming
    Replies: 3
    Last Post: 10-17-2011, 08:48 AM
  2. multiplication table
    By yatesj05 in forum C Programming
    Replies: 7
    Last Post: 04-17-2011, 03:46 AM
  3. C Multiplication Table
    By trueman1991 in forum C Programming
    Replies: 2
    Last Post: 11-11-2009, 07:58 AM
  4. Multiplication table
    By freddyvorhees in forum C++ Programming
    Replies: 6
    Last Post: 08-02-2008, 12:09 PM
  5. multiplication table help
    By cprogstudent in forum C++ Programming
    Replies: 2
    Last Post: 04-14-2002, 06:32 PM

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