fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. int i,j,sum=0,k=1;
  7. char p[10]; // using a char array to print spaces between number ans sun
  8. memset(p,'\0',sizeof p); // initialize array elements to null
  9. for(i=1;i<=5;i++)
  10. {
  11. sum =0; // set sum to 0 in every iteration
  12. for(j=1;j<=i;j++)
  13. {
  14. printf(" ");
  15. }
  16.  
  17. for(j=i;j<=5;j++)
  18. {
  19. printf("%i",j);
  20. sum = sum + j;
  21. }
  22. if(k<10){ // this is to print space between number and sum
  23. memset(p,' ',k); // include number of space in string
  24. printf("%s",p); // print the string with space
  25. }
  26. k=k+2; // increment k by 2
  27. printf("%i",sum);
  28. printf("\n");
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
 12345 15
  2345   14
   345     12
    45       9
     5         5