Translate

Friday, April 17, 2020

Request the user for two integer and print their sum.

Sum of two numbers


#include<stdio.h>
#include<conio.h>
  void main()
{
  int a, b, sum;

/* Printf() outputs the values to the screen whereas scanf() receive them from the keyboard.
   and  &   is a address used in scanf(). */
 printf("enter  first no=");
  scanf("%d", & a);
  printf("enter second no=");
  scanf("%d", & b);
  sum= a+b;
  printf("Sum of two number is =%d",sum);
  getch();
}
Output:






 Useful Notes & Tips

 1.) semicolon(;) - end of statement  C statement must end with a semicolon because it's acts as an statement terminator.


2.)  a, b, sum are variables. Here, you can use x/y/z because variable is just a name that can be store values.  it is an identifiers whose value vary during program execution. 


3.)  & is a address used in scanf(). when we say &a or any variable name , we are telling the scanf() at which memory location  should it store the value supplied by the user from the keyboard.


 4.) main() is function. every C program must be contain one function that is called main() function because program execution always start with main().  

 

5.) Comment about the program should be enclosed within /*  write your comment */
 

6.) comment is not mandatory but it's indicating the purpose of the program so easy to understand by user or programmer.
 

7.) you can write a comment at any place.

 8.) we can comment in small, capital, or special character. there is no any rules because comments are completely ignored by the compiler. 


9.) stdio.h is a header file. it's stands for standard input output.  it contain printf() and scanf() function.


10. conio stands for console input output. it is used for following functions: clrscr(), getch().

No comments:

Post a Comment

C program to make a calculator using the switch statement.

/*perform arithmetic calculation on integers in C language*/ #include<stdio.h> #include<conio.h> void main() {     char op;     ...