fork download
  1. /* Sample Exercise 1
  2.  
  3.   Write a program to generate and display a table of
  4.   n and n squared, for integer values ranging from 1
  5.   to 10. Be sure to print appropriate headings.
  6. */
  7. #include <stdio.h>
  8. main ()
  9. {
  10.  
  11. int num; /* a series of numbers */
  12. int num_squared; /* each number squared */
  13.  
  14. printf ("TABLE OF SQUARES FOR 1 TO 10\n\n");
  15. printf (" num num squared\n");
  16. printf ("----- -----------\n");
  17. /* loop from 1 to 10 */
  18. for (num = 1; num <= 10; ++num )
  19. {
  20. printf (" %d %d\n", num, num*num);
  21. }
  22. return (0);
  23. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
TABLE OF SQUARES FOR 1 TO 10

 num      num squared
-----     -----------
  1         1
  2         4
  3         9
  4         16
  5         25
  6         36
  7         49
  8         64
  9         81
  10         100