Thread: Problem with printing shape (square of number)

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    1

    Problem with printing shape (square of number)

    Hello. I am new to this forum as well as an amateur in programming. My lecturer gave me homework where the user should enter the height of the square they want to see. for example:
    Height: 4

    output
    4 8 12 16
    8 12 16 4
    12 16 8 4
    16 12 8 4

    this is what I've done so far, i know how to get the 1st row but I don't know how to swap the number for the next rows
    Code:
    #include <stdio.h>
    int main ()
    {
    int height,row,height1,num,num1;
    printf ("=================\n");
                    printf ("You pick square!\n");
                    printf ("Enter height you wish to see:\n");
                    scanf ("%d",&height);
                    num=height;
                    num1=height;
                    
                    for (row=1;row<=height;row++)
                    {
    
                        for (height1=1;height1<=height;height1++)
                        {
                            printf ("%d ",num1);
                            num1=num1+num;
                        }
                        num=num+num;
                        printf ("\n");
                    }
    return 0;
    }
    I've only cover 5 chapter so far which is sequence,loop,and function.I manage to do the other 3 shape our lecturer give us because the pattern is quite easy,but this,I just can't figure it out
    I hope someone can help me and comment on this thank you!
    Last edited by Fillow Ewik; 10-24-2015 at 08:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem printing histogram about number frequencies
    By Hana Nasser in forum C Programming
    Replies: 14
    Last Post: 03-17-2015, 02:47 AM
  2. Printing a Solid Square based on user input
    By ThatBoy1124 in forum C Programming
    Replies: 3
    Last Post: 03-01-2011, 10:07 PM
  3. How to confirm the number is square number?
    By Mathsniper in forum C Programming
    Replies: 5
    Last Post: 12-15-2006, 12:31 PM
  4. Printing a centric square using recursion
    By ChaosTheMatador in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 06:13 PM
  5. problem printing with floating number
    By ssharish in forum C++ Programming
    Replies: 4
    Last Post: 01-25-2005, 07:31 PM

Tags for this Thread