fork download
  1. #include <stdio.h>
  2. main ()
  3. {
  4.  
  5. int n; /* a number */
  6. int tri_num; /* the triangular value of the number */
  7.  
  8. printf ("TABLE OF TRIANGULAR NUMBERS by 5\n\n");
  9. printf (" n Triangular Number\n");
  10. printf ("--- -----------------\n");
  11.  
  12. tri_num = 0;
  13.  
  14. n = 5;
  15. do
  16. {
  17. tri_num = (n * (n + 1))/2;
  18. printf (" %d %d\n", n, tri_num);
  19. n = n + 5; /* better: n += 5; */
  20. }
  21. while (n <= 50);
  22. return (0);
  23. }
  24.  
  25. /* with a while loop */
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
TABLE OF TRIANGULAR NUMBERS by 5

 n     Triangular Number
---    -----------------
 5        15
 10        55
 15        120
 20        210
 25        325
 30        465
 35        630
 40        820
 45        1035
 50        1275