CSE Rockz Home Blog Links Forum VSF

Thursday, December 18, 2008

DAILY:2-CLASS PRACTICE

Class practice is a section similar to the renew section ...but what differs is this section deals with current section not the basic section and contains mostly the practice sessions held in the class...

1./*wap to get 

1
12
123
1234
12345
*/

main()
{
int i,j;

for(i=1;5>=i;i++)
{
for(j=1;5>=j;j++)
printf("%d",j);

printf("\n");
}


}


dry run:
  • analyse the pattern . .. . . .. .before writing the program
  • in the pattern the numbers are printed from 1 to 2,1 to 3 ..... 1-5 if generalized it's 1-n
  • the whole set is repeated 5 times such that n increases from 1-n in each repetition of above series
  • so the pattern is nothing but a repitition of 1-n in general which is inturn repeated n times.
  • so we cunstruct one loop to print 1-n and other to repaet this loop n times.

2./*
wap to print

5
54
543
5432
54321
*/

main()
{

int i,j;

for(i=5;i<=1;i--)
{

for(j=n;j>i;j--)
printf("%d",j);

printf("\n");
}


}

dryrun:
  • this prog is similar to the above program
  • here in the above pattern the numbers are repeated from n-1 in general
  • a loop is cunstructed in order to evaluate the pattern
  • this pattern is repeated n times and an according loop is cunstructed.
  • if i=1;i is less than5 and the loop is enterd if j=5 and j is more than thanor equal to i hence it prints frpm n-i or 5-1 so on .....all the two loops are executed .

3./* wap to print

12345
1234
123
12
1
*/

main()
{

int i,j;

for(i=5;i>0;i--)
{

for(j=1;j<=i;j++)
printf("%d",j);

printf("\n");

}





4./*wap to print 

5
45
345
2345
12345

*/

main()
{

int i,j;

for(i=1;i>0;)
{

for(j=i;j<=5;j++)
printf("%d",j);
printf("\n");
}


}

5./*

12345
2345
345
45
5

*/

main()
{

int i,j;

for(i=5;i>0;i++)
{

for(j=i;j<=5;j++)
printf("%d",j);
printf("\n");
}

}


6./*

54321
5432
543
54
5

*/

main()
{

int i,j;

for(i=5;i>0;i++)
{

for(j=5;j>=i;j--)
printf("%d",j);
printf("\n");

}



}

7./*

1
121
12321
1234321
123454321
*/

main()
{

int i,j,k;

for(i=1;i<=5;i++)

{

for(j=1;j<=i;j++)
printf("%d",j);

for(k=(i-1);k>0;k++)
printf("%d",k);

printf("\n");
}


}

8./*

123454321
1234321
12321
121
1
*/

main()
{

int i,j,k;

for(i=5;i>0;i--)
{

for(j=1;j<=i;j++)
printf("%d",j);

for(k=(i-1);k>0;k++)
printf("%d",k);

printf("\n");


}


}

9./*

5
545
54354
5432543
543215432
*/

main()
{

int i,j;

for(i=5;i<0;i--)>
{

for(j=i;j<=i;j--)
printf("%d",j);

for(k=5;k<=i-1;k--)
printf("%d",k);

printf("\n");


}




}

No comments:

Post a Comment