How to add two numbers in c programming?

Follow the ways to add two numbers

  • Open the "c" editor i.e turbo c.
  • goto file menu
  • click on new
  • a new source code will appear
  • then write the program in that source code(as below).


  • after that save the source code using "f2" key other wise goto file menu click on save command
  • then type the name of the program with extension ie.(.c) such (ram.c) here ram is the name of the program where as .c is the extension name of c language.
  • after saving go to compile menu of the source code then click on it or press alt+f9


  • after compilation it generates three files
    1.object file(.obj)
    2.executable file(.exe)
    3.back up file(.bak)
  • then go to run menu click on it or press ctrl+f9



  • to show out put result on the user interactive screen press alt+f5;
  • to close the source code then press alt+x.
In the following ways you can add two numbers very easily.


#include<stdio.h>

#include<conio.h>

main( )

{

int a=10,b=20,c=0;

clrscr( );

c=a+b;

printf("%d is the addition of two integers",c);

return 0;

}


or


#include<stdio.h>

#include<conio.h>

main( )

{

int a,b,c=0;

clrscr( );

printf("enter first number ");

scanf("%d",&a);

printf("enter second number ");

scanf("%d",&b);

c=a+b;

printf("%d is the addition of two integers",c);

return 0;

}

or


#include<stdio.h>

#include<conio.h>

main( )

{

int a,b,c=0;

clrscr( );

printf("enter two numbers ");

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

c=a+b;

printf("%d is the addition of two integers",c);

return 0;

}


No comments: