Wednesday, 3 August 2011

TO PRINT PATTERN


TO PRINT THE FOLLOWING PATTERN
                                     
                                        1
                                        2       3
                                        4       5       6
                                        7       8       9       10
                                        11     12     13     14     15     16
ALGORITHM
Step-1 Start
Step-2 Take the limit value from the user.
Step-3 Initialization of the variables for different tasks.
Step-4 Run the loop for number of lines.
Step-5 Run another loop inside loop started in step-3 for       
           printingnumbers.
Step-6 Print the numbers.
Step-7 Change the line
Step-8 Exit







PROGRAM
class pattern1
{
public static void main(int l)
{
int a,c,n=1;
for (a=1;a<=l;a++)
{
for (c=1;c<=a;c++)
{
System.out.print(n+"\t");
n++;
    }
    System.out.println();
}
    }
}

VARIABLE DESCRIPTION-

VARIABLE
USED
DATATYPE
DESCRIPTION
a
Integer type
For running loop for Change the lines
c
Integer type
For printing the numbers.
l
Integer type
For taking the limit range.
n
Integer type
Stores the numbers which has to be printed during the loop.







INPUT/OUTPUT

INPUT
OUTPUT

3
                    1
                    2        3
    4        5        6


4
                    1
                    2       3
  4       5        6
              7       8        9       10

No comments:

Post a Comment