Advertisement
Dany1858

Esercizio 3.2 (triangolo a scelta con funzione) NON TESTATO

Sep 8th, 2014
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.87 KB | None | 0 0
  1. /*Scrivere un programma C che acquisisca in input da tastiera un valore
  2. intero positivo N <= 40 corrispondente alla base di un triangolo rettangolo
  3. e isoscele, e che riproduca a video tale triangolo utilizzando il carattere ‘*’.
  4. Esempio:
  5. se il valore letto da tastiera è 3, a video dovrà essere visualizzata
  6. la seguente serie di caratteri
  7. *
  8. **
  9. ***     */
  10. /*Scrivere un programma C che acquisisca in input da tastiera un valore
  11. intero positivo N <= 40 corrispondente alla base di un triangolo
  12. isoscele, e che riproduca a video tale triangolo utilizzando il carattere ‘*’.
  13. Esempio:
  14. se il valore letto da tastiera è 3, a video dovrà essere visualizzata
  15. la seguente serie di caratteri
  16.   *
  17.  * *
  18. * * *         */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23.  
  24. void main()
  25. {
  26.  int base, i, j, k;
  27.  char risp, rispt;
  28.  
  29.   do{
  30.      do{
  31.         printf("Immettere base triangolo. Massimo 40\t");
  32.         scanf("%d", &base);}
  33.         while(base<0 || base>40);
  34.         printf("\nTriangolo rettangolo o isoscele? r o i\t");
  35.     scanf("%1s", &rispt);
  36.  
  37.         if(rispt=='r'){
  38.     for(i=0, j=0; i<=base; i++, j++){
  39.                  k=0;
  40.                  printf("\n");
  41.                  while(k<j){
  42.                  printf("* ");
  43.                  k++;}
  44.                  }
  45.     else if(rispt=='i'){
  46.     for(i=0, j=0; i<=base; i++, j++){
  47.                  x=0;
  48.                  y=base-j;
  49.                  while(x<y){
  50.                  printf(" ");
  51.                  x++;
  52.                  }
  53.                  k=0;
  54.                  while(k<j){
  55.                  printf("* ");
  56.                  k++;
  57.                  }
  58.                  printf("\n");}
  59.         }
  60.     else printf("Opzione errata");
  61.        
  62.        
  63.      printf("\n\nVuoi continuare? s o n\t");
  64.      scanf("%s", &risp);
  65.      if(risp=='s')
  66.      system("clear");
  67.      }
  68.   while(risp=='s');
  69.   system("PAUSE"); 
  70.   return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement