Computer Programming (2)


administrivia

Web Page - http://www.cs.tau.ac.il/~efif/courses/ComputerProgramming


a second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

new concepts


variables

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

loops


second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);
      
   return 0;
}

second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

second example

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   int i;
   for (i = 0; i < 10; i = i + 1)
      printf ("i is %d\n", i);

   return 0;
}

we could have written it like this…

/* This program prints a list of integers, from 0 to 9 */

#include <stdio.h>

int main (void)
{
   printf ("i is 0\n");
   printf ("i is 1\n");
   printf ("i is 2\n");
   printf ("i is 3\n");
   printf ("i is 4\n");
   printf ("i is 5\n");
   printf ("i is 6\n");
   printf ("i is 7\n");
   printf ("i is 8\n");
   printf ("i is 9\n");

   return 0;
}

ok, what's going on here?


remember what a program is


so what's a compiler?


so let's look at the whole process


let's talk about this variable concept…


variable declarations


variable names


data types


how to know which to use?


why have data types?


bits are fundamentally typeless


integral types


integral types continued


char – a special integral type


 text as numbers


what is ASCII?


more about character encoding


int


double


let's look at an example

/*
 * Print a Fahrenheit-to-Celsius
 * conversion table
 */

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

what does this do?


let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
} 

let's look more closely

#include <stdio.h>

int main (void)
{
   int fahr;
   int celsius;
   int lower = 0;
   int upper = 300;
   int step = 20;

   fahr = lower;
   while (fahr <= upper) {
      celsius = 5 * (fahr – 32) / 9;
      printf ("%d\t%d\n", fahr, celsius);
      fahr = fahr + step;
   }

   return 0;
}   
lectures prev top next
Maintained by Efi Fogel. Last modified: May 31 2003.