Wednesday, November 19, 2014

loop

/* Task 1

****
***
**
*


#include<stdio.h>

int main()
{
int i, j;

for (i = 4; i >= 0; i--)
{
for (j = i; j>0; j--)
{
printf("*");
}
printf("\n");
}
}

*/

/* Task 2

*
**
***
****

#include<stdio.h>

int main()
{
int i, j;

for (i = 0; i <= 4; i++)
{
for (j = 0; j<i; j++)
{
printf("*");
}
printf("\n");
}
}

*/

/* Task 3

   *
  * *  
 * * *
* * * *

#include<stdio.h>

int main()
{
int i, j, k;

for (i = 0; i <= 4; i++)
{
for (k = 1; k <= 4 - i; k++)
{
printf(" ");
}
for (j = 0; j<i; j++)
{
printf(" *");
}
printf("\n");
}
}

*/

/* Task 4

* * * *
 * * *
  * *
   *

#include<stdio.h>

int main()
{
int i, j, k;

for (i = 4; i >= 0; i--)
{
for (j = 0; j<i; j++)
{
printf(" *");
}
printf("\n");
for (k = 0; k <= 4 - i; k++)
{
printf(" ");
}
}
}
*/

/* Task 5

   *
  * *
 * * *
* * * * 
 * * *
  * *
   *


#include<stdio.h>

int main()
{
int  i, j, k;

for (i = 0; i <= 4; i++)
{
for (int j = 1; j <= 4 - i; j++)
{
printf(" ");
}
for (int j = 0; j<i; j++)
{
printf(" *");
}
printf("\n");
}

for (i = 2; i >= 0; i--)
{
for (k = 2 - i; k >= 0; k--)
{
printf(" ");
}
for (j = i; j >= 0; j--)
{
printf(" *");
}
printf("\n");
}

}

*/

No comments:

Post a Comment