first
, second
and third
, finds out if the numbers are in strictly descending order (first > second > third
). Is there an alternative way to write this program?
1 #include <stdio.h> 2 3 int main(int argc, char* argv[]){ 4 int first, second, third; 5 printf("Enter numbers: "); 6 scanf("%d %d %d", &first, &second, &third); 7 8 return 0; 9 }
% ./stars Enter : 5 * * * * *
1 #include <stdio.h> 2 3 int main( void ) 4 { 5 int num; 6 int row, col; 7 8 // Obtain input 9 printf("Enter number: "); 10 scanf("%d", &num); 11 for(col = 1; col <= num; col++){ 12 printf("*"); 13 } 14 printf("\n"); 15 16 for(row = 2; row < num; row++) { 17 for(col = 1; col <= num; col++) { 18 if(col == 1 || col == num){ 19 printf("*"); 20 }else{ 21 printf(" "); 22 } 23 } 24 printf("\n"); // Start a new line 25 } 26 27 for(col = 1; col <= num; col++){ 28 printf("*"); 29 } 30 printf("\n"); 31 32 return 0; 33 }What is the output if the user types in the number 4?
Modify the program so that it prints a triangle instead of a square:
$ ./triangle Enter n ? 6 * ** *** **** ***** ******How would you change your program to print the triangle in different orientations?
(a) ****** (b) ****** (c) * ***** ***** ** **** **** *** *** *** **** ** ** ***** * * ******
'0'
to '9'
'A'
to 'Z'
'a'
to 'z'