C PROGRAM TO FIND SUM OF TWO NUMBERS


THIS IS THE PROGRAM FOR ADDING TWO NUMBERS.

 Here is the code for it -

 #include<stdio.h>
  int main()
  int a,b;

  printf("Enter two numbers to get their sum");

  scanf("%d%d",&a,&b);

  printf("The sum of %d and %d is %d",a,b,a+b);

  return 0;
 }
 

 OUTPUT - Enter two numbers to get their sum 4 8

 SUM - 12


You can use getch(); instead of return 0; if you are using codeblocks.

🔽Here is another way to write the same prgram using the sum function.

  

   #include<stdio.h>

 

     int main()

 {

     int a, b, sum;

 

     printf("\nEnter two no: ");

     scanf("%d %d", &a, &b);

 

      sum = a + b;

 

       printf("Sum : %d", sum);

 

      return 0;

   }

No comments:

Post a Comment