0% found this document useful (0 votes)
6 views

Class 7

Uploaded by

sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Class 7

Uploaded by

sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

///////////////////printing patterns////////////////////////////////////////////

6
6 5
6 5 4
6 5 4 3
6 5 4 3 2
6 5 4 3 2 1
outer loop
no of lines -6 outer loop 6 times
n
i=1; i<=n; i=i+1; i=n;i>=1 ,i=i-1
dn
inner loop
dn=n dn>=n-i+1 ; dn=dn-1;
// dn =6
6>=6-1+1 ; 5>=6-1+1=6//not valid so loop terminates

i=2;
dn=6 dn>=6-2+1 6>=5 dn=4 4>=6-2+1 ///true

o/p:

6
6 5
6 5 4
6 5 4 3

/////////program code//////////////////////
#include<stdio.h>
void main()
{
int i , n ,dn;
printf("enter number:");
scanf("%d",&n);
i=1 ;
while(i<=n)
{
printf("\n");
dn=n;
while(dn>=n-i+1)
{
printf("%d",dn);
dn=dn-1;
}
i=i+1;
}

/////////////////////////////////////////////////o/p////////////////////////////
////
enter number: 6
6
5 6
4 5 6
3 4 5 6
2 3 4 5 6
1 2 3 4 5 6

no of lines :6 //n
outer loop
i=1 i<=n i=i+1
in
inner loop

in in<=n in=in+1
n , i
in=6 n=6 i=1
i=2 n =6 in=5
5 n i

i =1
in=n+i+x
6=6+1+x
x=-1
i=1
--> in=n+i-1
in=6 6<=6 //true
in=7 7<=6 //false
i=2
---> in=6+2-1=7
in=7 7<=6 //false

///i=1
in=n-i+x
6= 6-1+x
x=1
in=n-i+1
i=1
in=6 6<=6 //true 7<=6//false

expression 2:in=n-i+x
6=6-1+x
x=1
i=1
in =n-i+1
6-1+1 =6 6<=6 //true
i=2
in=6-2+1 =5 5<=6

6
5 6

////////////////////////////////////////////////////////////////////////////////
///////////
7
7 6 7
7 6 5 6 7
7 6 5 4 5 6 7
7 6 5 4 3 4 5 6 7
7 6 5 4 3 2 3 4 5 6 7
7 6 5 4 3 2 1 2 3 4 5 6 7

the above code is split into 2 parts

7
7 6
7 6 5
7 6 5 4
7 6 5 4 3
7 6 5 4 3 2
7 6 5 4 3 2 1

7
6 7
5 6 7
4 5 6 7
3 4 5 6 7
2 3 4 5 6 7
i=1
s=n-i =7-1 =6 s>=1 pf(" "); s=s-1
i=2
s=n-2 =5 s>=1

s=n-i+x
6=7-1+x
x=0
i=1
s=6 6>=1 // 3
.

i=2
s=7-2=5 5>=1//
.

try this
*
* *
* * *
* * * *

You might also like