Write a C program to get the salary from the user and print it
Description: Ask the user to enter a salary. Store it in a variable and print it on the screen.
Hint:
- Use a
floatvariable and the%fformat specifier.
C program to read and print the salary
#include <stdio.h>
int main(void) {
float salary;
printf("Enter the salary: ");
scanf("%f", &salary);
printf("Your salary is %.2f\n", salary);
return 0;
}
Output:
Output of the above program is
Enter the salary: 45000.50
Your salary is 45000.50
How it works
scanf()reads the number typed by the user and stores it at the address ofsalary(&salary).%.2fprints the value with two digits after the decimal point.
Read C printf and scanf.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |