Aim: Addition of two values.
As mentioned in earlier post (Comments in C language), we'll see in this program about multi line comment.In this program we'll do (Algorithm of program):
- take two values from user.
- Store that values in different Variables (here a and b are variable)
- Make equation to addition of that two values and store in respective variable (here Sum is variable)
- And finally print / show that value to user
Let's go to program for better understanding.
Program:
(1) When you run program:
Due to printf Function output Screen will show "Enter Number A:" As per coding.
(2) Now type any number:
When type number "18" and press Enter Key, C compiler will save 18 value in variable "a" with the help of scanf function.
(4) Finally got answer
Due to Equation: "Sum=a+b", Variable 'Sum' have value addition of variable a and b.
And output screen will show it as per coding.
printf( ) :
This function is used to print the “character, string, integer, float, octal and hexadecimal values” onto the output screen.Use of printf() function with
%d
format specifier to display the value of an integer variable.Similarly
%f
for float variable, %lf for double, %c is used to display character, %s
for string variable, and %x
for hexadecimal variable.To generate a new line, “\n” in C printf() statement.
Scanf( ) :
This function is used to read "character, numeric data, string" from keyboard.To get character value is assigned to the variable “ch”.
To get string value is assigned to the variable “str”.
We'll see variables in future posts step by step...
If you're not familiar with variable see detailed example of variable...
See Also:
What is Datatype ? Explore Datatype with Example ...
1 comment:
Hi, thanks for your blog, if you want to learn about programming languages like java, php, android app, embedded system etc. I think this training institute is the best one.
best python training in coimbatore
Android training in coimbatore
Networking training in coimbatore
Post a Comment