L-1 MCS 260 Mon 20 Aug 2001

Below are listings for programs we discussed in class.
/* L-1 MCS 260 Mon 20 Aug 2001 : our first C program */

#include <stdio.h>

int main(void)
{
   printf("Hello world!\n");
   return 0;
}
Our second program shows how to calculate in C.
/* L-1 MCS 260 Mon 20 Aug 2001 : C as calculator */

#include <stdio.h>

int main(void)
{
   int ft_height = 1707;      /* height of Sears Tower */
   int ft_to_cm = 30;         /* 1 ft = 30 cm */
   int m_to_cm = 100;         /* 1 m = 100 cm */
   int cm_height,m_height;    /* variables to convert to metric system */

   printf("Welcome to Chicago!\n");
   printf("Its tallest building is the Sears Tower:\n");
   printf("  %d ft tall (including the antennas)\n", ft_height);

   cm_height = ft_height * ft_to_cm;      /* convert ft to cm */
   m_height = cm_height/m_to_cm;          /* integer division truncates */
   cm_height = cm_height%m_to_cm;         /* remainder of division */

   printf("  = %d m %d cm in the metric system.\n", m_height, cm_height);
   
   return 0;
}