Use scanf to get input from a standard input device, such as a keyboard : scanf Basics « printf scanf « C Tutorial






In scanf, you have to specify the address of a variable, such as &i, &j, and a list of format specifiers (%d). The number of format specifiers must be the same as the number of variables.

#include <stdio.h>

main(){
  int i,j,k;
  printf("Input two integers and press Enter to comfirm:");

  scanf("%d%d",&i,&j);
  k = i + j;
  printf("sum of two numbers is %d \n",k);
}
Input two integers and press Enter to comfirm:223
     2
     sum of two numbers is 225








4.20.scanf Basics
4.20.1.scanf
4.20.2.Using Scanf to Receive Input from a User
4.20.3.The scanf placeholders
4.20.4.Use scanf to get input from a standard input device, such as a keyboard
4.20.5.Pass pointer argument to scanf
4.20.6.Using an inverted scan set
4.20.7.Reading and discarding characters from the input stream