0% found this document useful (0 votes)
31 views3 pages

Sampleprogram

The document requests a review of a video on taking input from the user in C programming and provides a sample program to demonstrate it. The sample program takes two integer values from the user as input and performs basic arithmetic operations - addition, subtraction, multiplication and division - on the values. It displays the results of each operation on separate lines as output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

Sampleprogram

The document requests a review of a video on taking input from the user in C programming and provides a sample program to demonstrate it. The sample program takes two integer values from the user as input and performs basic arithmetic operations - addition, subtraction, multiplication and division - on the values. It displays the results of each operation on separate lines as output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Review video on TAKING VALUE FROM

THE USER, explain how you understand it


and give me a sample program, somehow
slight similar to my example, explain it line
by line. DEADLINE: Thursday @4:00pm

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.

sum = a + b; // this enables to calculate the addition using ‘+’ symbol

sub = a - b; // this enables to calculate the subtraction using ‘-‘ symbol

mul = a * b; // this enables to calculate the multiplication using ‘*’ symbol


div = a / b; // this enables to calculate the division using ‘/’ symbol

printf(“Addition: %d \n”, sum); //this will display the result of addition

printf(“Subtraction: %d \n”, sub); //this will display the result of subtraction

printf(“Multiplication: %d \n”, mul); // this will display the result of multiplication

printf(“Division: %d \n”, div); // this will display the result of division

return 0; // this is the termination part of the program

THE CODE WITHOUT THE COMMENTS:

#include <stdio.h>

int main()

int a,b;

int sum,sub,mul,div;

printf(“Please enter the first value: \n”);

scanf(“%d”, &a);

printf(“Please enter the second value: \n”);

scanf(“%d”, &b);

sum = a + b;

sub = a - b;

mul = a * b;

div = a / b;

printf(“Addition: %d \n”, sum);

printf(“Subtraction: %d \n”, sub);


printf(“Multiplication: %d \n”, mul);

printf(“Division: %d \n”, div);

return 0;

You might also like