/*
this program sums integers from a to b, inclusive
composed by the 10.001 class
9/12/02

Defensive check for a < b, added after class...
-GCR
*/

#include < stdio.h>

int main(void)
{
   int a,b,sum,temp;

   /* step 1: get a and b from user*/
   printf("input two integers, a and b\n");
   scanf("%d %d",&a,&b);

   /* step 2: check for a < b, swap if necessary: */
   if(a > b) {
     temp = a;
     a = b;
     b = temp;
   }

   /* step 3: prepare first part of output message, before a is changed */
   printf("the sum from %d to %d is ",a,b);

   /* step 4: initialize sum and loop until all values are added to it */
   sum=a;
   while(a < b)
   {
     sum=sum+a;
   }

   /*step 5: complete output message
   (only works if no printf statements come between step 3 and step 5)*/
   printf("%d\n",sum);

   return(0);
}