[Courses] C Programming For Absolute Beginners, Lesson 2: Fun With Printf, Scanf, Puts, and Variables
Leslie
leslie.brothers at verizon.net
Thu Feb 23 04:58:04 UTC 2012
On Mon, 2012-02-20 at 20:26 -0800, Carla Schroder wrote:
>
> Homework: Modify the addition program to echo the user input as it is entered,
> so it looks something like this:
>
> "Please enter any number up to three digits:
> 34
> You entered the number 34. Now please enter another number:"
>
I am "turning in my homework" just to be traditional and in case it can
help anyone else. I did the plain vanilla version as above. A simple
assignment was fine because then I could spend some time on the helpful
side-lessons. Plenty to digest!
#include <stdio.h>
int main()
{
int a, b, c;
puts( "Please enter any number up to 3 digits: " );
scanf( "%d", &a );
printf( "You entered %d. ", a);
puts( "Please enter another number up to 3 digits: " );
scanf( "%d", &b );
printf( "You entered %d.\n", b);
c = a + b;
printf("%d + %d = %d\n", a, b, c);
return 0;
}
-Leslie
More information about the Courses
mailing list