fork download
  1. #include <stdio.h>
  2.  
  3.  
  4. main()
  5. { //begin program
  6.  
  7.  
  8.  
  9. printf("\nNama\t: Muhammad Rizqi Subeno");
  10. printf("\nNIM\t: I0717032");
  11. printf("\nTugas\t: Teknik pemrograman soal 3b - create character 2\n\n");
  12.  
  13.  
  14. //initialize variable i and x for counter
  15. //initialize variable n for input length for character
  16. int i,n,x;
  17. do //do-while looping when input n <= 1 then get input n again until n value >0
  18. {
  19. printf("masukkan n : "); //print to screen 'masukkan n'
  20. scanf("%d",&n); //get user input and enter input to n variable
  21. }
  22. while(n < 1);
  23.  
  24. for(x = 1; x<=n;x++) //for-looping for looping from x=1 to n value part 1.
  25. {
  26.  
  27. for(i=n; i>x-1; i--) // for looping decrease character from n value to x-1 value in left part
  28. {
  29. printf("*"); //print to screen ' * '
  30. }
  31. if(x != 1) //if x is not same 1 then
  32. {
  33. for (i = 1;i<=(x*2-2);i++) //for-looping for determine sum of print space
  34. {
  35. printf(" "); //print space to screen
  36. }
  37. }
  38. for(i=n; i>x-1; i--) //for looping decrease character from n value to x-1 value in right part
  39. {
  40. printf("*"); //print to screen ' * '
  41. }
  42. printf("\n"); //to change the line after print ' * ' characters
  43. }
  44.  
  45.  
  46.  
  47. for(x = 2; x<=n;x++) //for-looping for looping from x=2 to n value part 2.
  48. {
  49. for(i=1;i<=x;i++) //for looping increase character from 1 value to x value in left part
  50. {
  51. printf("*"); //print to screen ' * '
  52. }
  53. if(x != n) //if x value is not same with n value then
  54. {
  55. for(i=1;i<=((n*2)-(2*x));i++) //for-looping for looping from i = 1 to (n*2)-(n*x)
  56. {
  57. printf(" "); //print space to screen
  58. }
  59. }
  60. for(i=1;i<=x;i++) //for looping increase character from i=1 until i value <= x variable in right part
  61. {
  62. printf("*"); //print to screen ' * '
  63. }
  64. printf("\n"); //to change the line after print ' * ' characters
  65. }
  66. } //END.
  67.  
Success #stdin #stdout 0s 9432KB
stdin
10
stdout
Nama	: Muhammad Rizqi Subeno
NIM	: I0717032
Tugas	: Teknik pemrograman soal 3b - create character 2

masukkan n : ********************
*********  *********
********    ********
*******      *******
******        ******
*****          *****
****            ****
***              ***
**                **
*                  *
**                **
***              ***
****            ****
*****          *****
******        ******
*******      *******
********    ********
*********  *********
********************