Sampleprogram
Sampleprogram
The video ‘TAKING VALUE FROM THE USER’ tackles about the title of the video itself using C
Programming Language. This type of program will take a use of standard input and output using the
library <stdio.h>. Using the command ‘scanf’, this enables us to take the value from the user.
My sample program is to execute simple arithmetic operations at the same time by taking 2
different values from the user.
#include <stdio.h> // This is the preprocessor command to get the standard input and output
int main() // This is the main function and the start of the execution of the program
int a,b; // This two variables will be used to take values from the user
int sum,sub,mul,div; // These variables will be used to calculate the two values we will get
from the user
printf(“Please enter the first value: \n”); // this will be displayed to the user to get the first
value, the use of \n enables the user to input the value in the next line.
scanf(“%d”, &a); //this enables the user to give value to the variable a. We use “&a” to take a
role as “input” to give value to the variable a. If “&” is missing, the program will be dumped as fault.
printf(“Please enter the second value: \n”); // The same as the other one but this time it is for
the b variable.
scanf(“%d”, &b); // the same explanation as the other one but this time it is for the b variable.
#include <stdio.h>
int main()
int a,b;
int sum,sub,mul,div;
scanf(“%d”, &a);
scanf(“%d”, &b);
sum = a + b;
sub = a - b;
mul = a * b;
div = a / b;
return 0;