square.c

  #include <stdio.h>

  /*  A program to calculate a square area. */
  int main()
  {
     int width, length, area;

     width = 10;
     length = 5;
     area = width * length;
     printf("The dimension is %d by %d\n", width, length);
     printf("The area is %d.\n", area);
     return 0;
  }
  • Here, we declare three integer variables width, length, and area.
  • Then, we assign width to 10 and length to 5.
  • We calculate the area of the square by multiplying them, and store the result in a variable called area.
  • Note that star (*) sign is a sign for multiplication. For addition and subtraction, use + and - sign respectively. Division can use a slash (/). Remainder or modulo can be done using a percent sign (%).

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001

Hosted by www.Geocities.ws

1