Logo  

CS256 - Fundamentals of Structured Programming

Displaying exercises/e4/solution/h2.c

#include <stdio.h>
/**
 * Use the scanf function to get an integer value from the user and 
 * print the value squared and cubed.
 * Example input/output:
 * ./h2
 * 5
 * 25
 * 125
 */
int main(void)
{
  int num;

  // Best practice would be to check that scanf actually read a number.
  scanf("%d", &num);
  printf("%d\n", num*num);	// The square of num
  printf("%d\n", num*num*num);	// The cube of num

  return 0;
}