Looking for NEET / JEE Coaching? Enquire Now
You must Sign In to post a response.
  • Category: Programming

    Write a C++ program to print the required output using for loop.


    Preparing for Object Oriented Programming exam? Looking out for the correct solution for solving a problem using for loop? On this page ISC experts shall provide you with a program solution and detailed explanation to the problem.

    Following is a question that was asked in the question paper of B.E. E&E(December 2016)conducted by Bangalore University, for subject Object Oriented Programming(2K11 Scheme)(EE-305), Semester-III

    This question is asked for 10 marks and hence requires some explanation. Please let me know the solution.

    Q) Differentiate between break and continue statements. Write a program to print the following output using for loop. [10 Marks]

    Output required
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
  • Answers

    1 Answers found.
  • Below is the program to prepare required output. Please include iostream.h and conio.h header files before declaration of class.
    //PROGRAM TO PREPARE REQUIRED OUTPUT USING FOR LOOP.
    #include
    #include
    class sample
    {
    private:
    int n,r,c,d;
    public:
    void get(int t)
    {
    n=t;
    d=1;
    }
    void display(void)
    {
    cout<<"\nRequired output for "< for(r=1;r<=n;r++)
    {
    d=1;
    for(c=1;c<=r;c++)
    {
    cout< d++;
    }
    cout<<"\n";
    }
    }
    };
    void main(void)
    {
    class sample s;
    clrscr();
    int x;
    cout<<"\nEnter number of lines you needed\n";
    cin>>x;
    s.get(x);
    s.display();
    getch();
    }

    output-of-required-output-using-for-loop.docx

    Delete Attachment


  • Sign In to post your comments