/* ----------------------------------- */
/* exo1.c */
/* ------------------------------------ */

#include<stdio.h>

int main (void)
{
  int i;
  for (i=1;i<=50;i=i+1)
    {printf("%d ",i);};
  printf("\n");
  return 0;

}
/* ----------------------------------- */
/* exo2.c */
/* ------------------------------------ */


#include<stdio.h>

int main (void)
{
  int i;
  for (i=50;i>=1;i=i-1)
    {printf("%d ",i);};
  printf("\n");
  return 0;
}
/* ----------------------------------- */
/* exo3.c */
/* ------------------------------------ */


#include <stdio.h>

int main (void)
{
  int x,j;
  scanf("%d",&x);

  for (j=2;j<=x;j++)
    {
      if (j%2==0) 
	{printf("%d, ",j);}
      ;
    };
  
  printf("\n");
  return 0;
}
/* ----------------------------------- */
/*exos 4 et 5*/
/* ------------------------------------ */



#include <stdio.h>

int main (void)
{
  int x,j;
  int somme_tmp;
  
  somme_tmp = 0;

  for (j=1;j<=10;j++)
    {
      scanf("%d",&x);
      somme_tmp = somme_tmp + x;
      /*ajout pour l'exo 5*/
      printf("%d ieme somme intermediaire : %d\n",j,somme_tmp);
      /*fin ajout*/
    };
  
  printf("La somme est : %d \n",somme_tmp);
  return 0;
}
/* ----------------------------------- */
/*exos 6*/
/* ------------------------------------ */


#include <stdio.h>

int main (void)
{
  int x,j;
  int somme_tmp;
  double moy;
  
  somme_tmp = 0;

  for (j=1;j<=10;j++)
    {
      scanf("%d",&x);
      somme_tmp = somme_tmp + x;
    };
  
  moy = somme_tmp / 10.0;

  printf("La moyenne est : %f \n",moy);
  return 0;
}
/* ------------------------------------ */
/*exo 7*/
/* ------------------------------------ */

#include <stdio.h>

int main (void)
{
  int x,j;
  int somme_tmp,nb_strict_pos;
  double moy;
  
  somme_tmp = 0;
  /*compteur du nombre de donnees >0*/
  nb_strict_pos = 0;

  for (j=1;j<=10;j++)
    {
      scanf("%d",&x);

      if (x>0) /*si le chiffre donne est >0*/
	{
	  somme_tmp = somme_tmp + x;        /*augmenter la somme*/
	  nb_strict_pos = nb_strict_pos +1; /*augmenter le compteur*/
	}
    };

  /* remarquer la conversion ci-dessous */
  moy = ((double) somme_tmp) / ((double) nb_strict_pos) ;
  printf("La moyenne des >0 : %f  \n",moy);
  return 0;
}
/* ------------------------------------ */
/*exo8.c*/
/* ------------------------------------ */

#include<stdio.h>

/* remarquer que les fonctions auxiliaires ont un rsultat de type */
/* "void", cad "rien". Elles ne font qu'imprimer le motif demande */

void affiche_motif1(int taille)
{
  int i,j;
  for (i=1;i<=taille;i=i+1)
    {
      for (j=1;j<=taille;j=j+1)
	{printf("*");};
      printf("\n");
    };
}


/* motif 2 : nombre de lignes = taille */
/* et nb etoiles = numero de la ligne */

void affiche_motif2(int taille)
{
  int i,j;
  for (i=1;i<=taille;i=i+1)
    {
      for (j=1;j<=i;j=j+1)
	{printf("*");};
      printf("\n");
    }; 

}



/* motif 3 : nombre de lignes = taille */
/* puis sur la ligne i : taille - i espaces, puis i etoiles */

void affiche_motif3(int taille)
{

  int i,j;
  for (i=1;i<=taille;i=i+1)
    {
      for (j=1;j<=taille-i;j=j+1)
	{printf(" ");};
      for (j=1;j<=i;j=j+1)
	{printf("*");};

      printf("\n");
    };
}

/* motif 4 : nombre de lignes = taille */
/* sur la ligne i=1, taille -1  espaces puis 1 etoile */
/*   sur la ligne i>1, taille - i espaces,  */
/*   puis 1 etoile */
/*   puis 2*(i-1)-1 blancs */
/*   puis 1 etoile */

void affiche_motif4(int taille)
{

  int i,j;


  for (j=1;j<=taille-1;j=j+1)
    {
      printf(" ");
    };
  
  printf("*\n");        

  for (i=2;i<=taille;i=i+1)
    {
      for (j=1;j<=taille-i;j=j+1)
	{printf(" ");};
      printf("*");
      for (j=1;j<=2*i-3;j=j+1)
	{printf(" ");};
      printf("*");
      printf("\n");
    };
}


int main (void)
{

  int taille,motif;
  motif = 1;

  printf("Numero du motif \n");
  scanf("%d",&motif);


  printf("Taille du motif \n");
  scanf("%d",&taille);

    
  if (motif == 1) 
    {
      affiche_motif1(taille);
      return 0;
    }

  if (motif == 2) 
    {
      affiche_motif2(taille);
      return 0;
    }


  if (motif == 3) 
    {
      affiche_motif3(taille);
      return 0;
    }


  if (motif == 4) 
    {
      affiche_motif4(taille);
      return 0;
    }

/*si le motif est different de 1,2,3,4, on se retrouve ici, ce qui est ok */
  
  return 0;
}
