1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
Welcome to our Education website, plz like our page facebook to support us. Thank You and wish you good navigation

Dessiner un triangle avec langage C en utilisant Printf

abdelouafiJun 8, 2017

    1. abdelouafi

      abdelouafi Administrator Staff Member

      Messages:
      197
      Likes Received:
      9
      Trophy Points:
      18
      Joined
      Sep 13, 2016
      Exercice 1:
      On vous demande d'écrire un programme en langage C qui permet d'afficher un triangle en utilisant le caractère étoile (*) ? Vous pouvez utiliser l'instruction Printf pour résoudre ce problème.

      [​IMG]


      Exercice 2:
      Ecrire un programme en C qui permet d'afficher un losange comme suit:
      langage c dessiner etoile.png
       
      Last edited: Jun 12, 2017
      Loading...
      Exercice 1:
      Code:
      #include<stdio.h>
      
      main(){
      //int n=5;
          /*
          printf("%5s\n","*");
          printf("%4s%2s\n","*","*");
       
          printf("%3s%4s\n","*","*");
       
          printf("%2s%6s\n","*","*");
       
          for(int i=1;i<=9; i++) printf("%s","*");
       
          */
       
          int k=2;
          int n=6;
       
          printf("%*s\n",n,"*");
          for(int i=n-1;i>1;i--) 
          {
           
              printf("%*s%*s \n",i,"*",k,"*");
              k=k+2;
          }
          for(int i=1;i<=n+n-1; i++) printf("%s","*");
       
       
       
      }
      Explication détaillée en vidéo:




      Exercice 2:
      Code:
      #include<stdio.h>
      
      
      main(){
          int i,j,k;
         
              printf("%5s\n","*");
              printf("%4s%2s\n","*","*");
           
              printf("%3s%4s\n","*","*");
              printf("%2s%6s\n","*","*");
             
              for(int i=1;i<=9;i++) {
                 
                  printf("%s","*");
              }
              printf("\n");
              printf("%2s%6s\n","*","*");
                  printf("%3s%4s\n","*","*");
                  printf("%4s%2s\n","*","*");
                  printf("%5s\n","*");
             
             
          }

Share This Page

Share