User Input with scanf()
c
#include <stdio.h>
int main() {
int age;
float salary;
char name[50];
printf("Enter your name: ");
scanf("%s", name);
printf("Enter age: ");
scanf("%d", &age);
printf("Enter salary: ");
scanf("%f", &salary);
printf("Name: %s
", name);
printf("Age: %d, Salary: %.2f
", age, salary);
return 0;
}Important! scanf reads only one word (stops at space). Use fgets() for full line with spaces:
fgets(name, 50, stdin);Multiple Inputs
c
int a, b, c;
printf("Enter 3 numbers: ");
scanf("%d %d %d", &a, &b, &c);
printf("Sum = %d
", a+b+c);