Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Scrivere un programma C che acquisisca in input da tastiera un valore
- intero positivo N <= 40 corrispondente alla base di un triangolo rettangolo
- e isoscele, e che riproduca a video tale triangolo utilizzando il carattere ‘*’.
- Esempio:
- se il valore letto da tastiera è 3, a video dovrà essere visualizzata
- la seguente serie di caratteri
- *
- **
- *** */
- /*Scrivere un programma C che acquisisca in input da tastiera un valore
- intero positivo N <= 40 corrispondente alla base di un triangolo
- isoscele, e che riproduca a video tale triangolo utilizzando il carattere ‘*’.
- Esempio:
- se il valore letto da tastiera è 3, a video dovrà essere visualizzata
- la seguente serie di caratteri
- *
- * *
- * * * */
- #include <stdio.h>
- #include <stdlib.h>
- void main()
- {
- int base, i, j, k;
- char risp, rispt;
- do{
- do{
- printf("Immettere base triangolo. Massimo 40\t");
- scanf("%d", &base);}
- while(base<0 || base>40);
- printf("\nTriangolo rettangolo o isoscele? r o i\t");
- scanf("%1s", &rispt);
- if(rispt=='r'){
- for(i=0, j=0; i<=base; i++, j++){
- k=0;
- printf("\n");
- while(k<j){
- printf("* ");
- k++;}
- }
- else if(rispt=='i'){
- for(i=0, j=0; i<=base; i++, j++){
- x=0;
- y=base-j;
- while(x<y){
- printf(" ");
- x++;
- }
- k=0;
- while(k<j){
- printf("* ");
- k++;
- }
- printf("\n");}
- }
- else printf("Opzione errata");
- printf("\n\nVuoi continuare? s o n\t");
- scanf("%s", &risp);
- if(risp=='s')
- system("clear");
- }
- while(risp=='s');
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement