Video Link: https://youtu.be/17gp5DJEyiw Tutorial Link: https://www.programiz.com/c-programming/c-input-output
#include <stdio.h>
int main() {
int age;
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Output
22
Age = 22
#include <stdio.h>
int main() {
int age;
printf("Enter input value: ");
scanf("%d", &age);
printf("Age = %d", age);
return 0;
}
Output
Enter input value: 22
Age = 22
#include <stdio.h>
int main() {
double number;
char alphabet;
printf("Enter double value: ");
scanf("%lf", &number);
printf("Enter character value: ");
scanf("\n%c", &alphabet);
printf("Number: %lf", number);
printf("\nCharacter: %c", alphabet);
return 0;
}
Output
Enter double value: 22.1
Enter character value: z
Number: 22.100000
Character: z
#include <stdio.h>
int main() {
double number;
char alphabet;
printf("Enter input values: ");
scanf("%lf %c", &number, &alphabet);
printf("Number: %lf", number);
printf("\nCharacter: %c", alphabet);
return 0;
}
Output
Enter input values: 30.6
c
Number: 30.600000
Character: c
Q. What is the correct way to take double input?
Options
- scanf("%d", &input);
- scanf("%f", &input);
- scanf("%lf", &input);
- scanf("%c", &input);
Answer: 3