Date création : 07-11-2007 00:00:00 Date de la dernière modification : 12-01-2008 18:02:33
 Vous êtes dans : Langage C Astuces / Exercices
Ennoncé
Création d'un losange avec des étoiles
La solution
#include<stdio.h>
int i, j, size;
char r[10][10];
int main()
{
printf ("\n Enter the size of the rhombus size = "); scanf("%d", &size);
printf("\n");
for (i=0;i<2*size-1;i++)
{
for(j=0;j<2*size-1;j++)
{
if(((i==0) || (i==2*(size-1))) && (j==size-1))
{
r[i][j]='*';
printf("%c", r[i][j]);
}
else
{
if (i<size)
{
if(((j==size-i-1) || (j==size+i-1)) && (i!=0))
{
r[i][j]='*';
printf("%c", r[i][j]);
}
else
{
r[i][j]=' ';
printf("%c", r[i][j]);
}
}
else
{
if(((j==i-size+1) || (j==3*size-i-3)) && (i!=0))
{
r[i][j]='*';
printf("%c", r[i][j]);
}
else
{
r[i][j]=' ';
printf("%c", r[i][j]);
}
}
}
}
printf("\n");
}
printf("\n\n");
|
Exécution
silviu@jars-desktop:~/Desktop/Programs$ make romb
make: `romb' is up to date.
silviu@jars-desktop:~/Desktop/Programs$ ./romb
Enter the size of the rhombus size = 6
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
silviu@jars-desktop:~/Desktop/Programs$
Enter the size of the rhombus size = 12
*
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
|
Explication
|