The for loop as a block

/* Program : The for loop as a block */
    #include <iostream.h>
    void main()
    {
        int i , j , num ;
         cout<<"Enter the number of rows to be printed (from 1 to 10): \n";
        cin>>num;
        for (i=1 ; i<=num ; i++)
        {
            for (j=1 ; j<=i ; j++)
                cout<<"*\t";
            cout<<"\n";
        }
    }

----------------------------------------


/* Program: The for loop as a block */
    #include <iostream.h>
    void main()
    {
        int i , j ;

            for (i=1 ; i<=3 ; i++)                   /* Outer For Loop */
            for (j=1 ; j<=2 ; j++)             /* Inner For Loop */
                cout<<"Hello!"<<endl;
    }
-------------------------------------------
/* Program: The for loop as a block */
    #include <iostream.h>
    #include<conio.h>
    void main()
    {
        int x , y , z = 0 ;
        clrscr() ;
        cout<<"The Fibonacci Series :\n";
        cout<<"====================\n";
        cout<<"0\n1\n";
        for (x=0,y=1 ; y<1000 ; x=z)
        {
            z = y ;
            y = x + y ;
            cout<<y<<endl ;
        }
    }

-----------------------------------------------
/* Program: The for loop as a block */
    #include <iostream.h>
    void main()
    {
        int num , square , cube ;
        cout<<"The squares and cubes of first ten numbers :\n";
        cout<<"==========================================\n\n";
        cout<<"Number\tSquare\tCube\n";

        for (num=1 ; num<11 ; num++)
        {
            square = num * num ;
            cube = num * square ;
            cout<<num<<"\t"<<square<<"\t"<<cube;
        }
    }

-------------------------------




0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|