Thread: Help Solving this loop problem (Multiplication table)

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    90

    Help Solving this loop problem (Multiplication table)

    Hi all, i was having trouble solving this problem,

    Writ a program to read a number n using keyboard where n must be >2.Then program display the multiplication table n rows,n columns and table's entity is i x j. Where i=1,2,...n
    j=1,2,...n.
    Display each table row in a new horizontal line.


    here is my work so far:
    Code:
    #include <stdio.h>
    #include <conio.h>
    main()
     {
    int i,j,N;
    if (N>2)
    printf("Please enter a value greater than 2");
    scanf("%d",&N);
        for(i=1;i<=N;i++)
    {
        for(j=1;j<=N;j++)
      {
      printf("%d\t",i*j);
      }
    
    printf("\n");
    }
    getch();
     }

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Ok, so is this just a report or a question?
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    for God's sake stop making 3 threads for the same question.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help me as fast as possible
    By Xbox999 in forum C Programming
    Replies: 5
    Last Post: 11-30-2009, 06:53 PM
  2. Addition problem in loop
    By murjax in forum C Programming
    Replies: 3
    Last Post: 07-01-2009, 06:29 PM
  3. validation problem in a loop (newbie question)
    By Aisthesis in forum C++ Programming
    Replies: 11
    Last Post: 05-10-2009, 10:47 PM
  4. weired problem in while loop
    By avisik in forum C Programming
    Replies: 14
    Last Post: 12-01-2008, 01:41 PM
  5. multiplication table
    By SpEkTrE in forum C Programming
    Replies: 2
    Last Post: 12-09-2003, 04:46 PM