Tell me the Ans

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angellove40
    New Member
    • Feb 2008
    • 2

    #1

    Tell me the Ans

    Q.1>Write a program to print the following output
    using for loops
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    ............... ......

    Q.2> Write a function using reference variables as arguments to swap the values of a pair of integers.

    Q.3>Write a function that creates a vector of user given size M using new operator
  • Simonius
    New Member
    • Feb 2008
    • 47

    #2
    We don't just give code.
    Show what you've attempted so far.

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

      Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

      Then when you are ready post a new question in this thread.

      MODERATOR

      Comment

      • billyusa
        New Member
        • Feb 2008
        • 5

        #4
        i have similar problem with that of hers

        Assume that the int variables i , j and n have been declared, and n has been initialized. Write code that causes a "triangle" of asterisks to be output to the screen, i.e., n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consisting of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be (scroll down if necessary):
        *
        **
        ***

        my work is as how

        for (i=1; n <=j; i++)
        {cout << n - (i * 2);
        cout << n - i;
        cout << n + j;

        }
        please help as I really dont understand this stuff, and teacher doesnt explainw ell and book we use is of no use as it just covers same topic from chapter 1 ofver and over giving no real help


        thanks in advance

        Comment

        • Simonius
          New Member
          • Feb 2008
          • 47

          #5
          Your logic is a bit faulty.

          This should do the trick

          Code:
          for(i = 0; i < AmmountOfRows; ++i){
                  for(j=0;j<i;++j)
                      cout<<"*"
                  cout<<endl;
          }
          This is basicly your logic:
          You want to loop untill you have the desired ammount of rows, that's the first line.
          Then you want to make a loop that prints a * untill there are as many stars on that line as the line number. That's the second and third line of coding.
          Then after all the stars for that line are printed you need a new line, that's the fourth line.

          This is just a basic usage of loops.
          If you can't figure it out I suggest trying to write down what you need to do, or imagine what you want the completed program to do if you step through it.

          Comment

          • billyusa
            New Member
            • Feb 2008
            • 5

            #6
            thanks i got it down I think,

            Comment

            • angellove40
              New Member
              • Feb 2008
              • 2

              #7
              Thanks Buddy [B],
              Its really worked i just put "i" instead of * and my prob got solved.

              Comment

              Working...