Oct 9, 2012

Introducing scanf

scanf is an instruction that saves a number or value in a variable, is used after a printf. This time I'll use it for sum two numbers, the program will ask for that numbers and then show the result.

#include <stdio.h>

main()
{
      int st_num;
      int nd_num;
      int rslt;
     
      printf("Enter the first number right here ---> ");
      scanf ("%d", &st_num);
      printf("Enter the second number right here --> ");
      scanf ("%d", &nd_num);
      rslt = st_num + nd_num;
      printf("Your result is %d", rslt);
      getchar();
      getchar();
}

No comments:

Post a Comment