First program in C

First program in C

Program question :

Q. Write a c program to calculate addition of two numbers.

Ans :
       #include<stdio.h>
       #include<conio.h>
        void main()
        {
          int a,b,c;
         printf("Enter first numbers : ");
         scanf("%d",&a);
         printf("Enter secound number : ");
         scanf("%d",&b);

         /*add two numbers */
         printf("Addition of two numbers : ");
         c=a+b;
         printf("a+b=");  
         scanf("%d",&c);
         getch();
       }

Output : 
             Enter first number : 40
             Enter secound number : 40
             Addition of two numbers : 
             a+b=80

  In above program calculate the addition of two numbers. For addition required at least two numbers. In program a and b are two variables that declare to store two number by user, and another variable c are used to store an addition of two numbers.

  • printf() - Used to display message on screen. It is necessary  to use #include<stdio.h>. stdio.h is standard input output header file.
  • scanf() - Is used to read character, string, numeric data from keyboard. The format specifier %d is used in scanf() statement. So that, the value entered is received as an integer.
  • getch() - Is used to get a character from console. And holds the output screen. 

0 comments:

Post a Comment