answersLogoWhite

0

#include <stdio.h>

#include <conio.h>

int main()

{

int x;

int y;

int result;

printf("Enter the first number to be added: ");

scanf("%d",&x);

printf("Enter the second number to be added: ");

scanf("%d",&y);

result = x + y;

printf("Here is the result %d\n",result);

return(0);

getch();

}

Heres the low down:

1) The #include <stdio.h> includes the file stdio.h into your code so it knows what the functions such as printf() mean.

2) int main() is the main function you write most of your code in.

3) int x; , int y; , and int result. the int stands for integer or a number (no decimal points you need a float for that) the X and Y are the numbers you are adding together and result is the result of the numbers.

4) printf("Enter the first number to be added: ");

scanf("%d",&x); the Printf() prints the text, Enter the first number to be added: , onto the screen and the scanf("%d",&x); looks for the number input from the keyboard for x.

5) printf("Enter the second number to be added: ");

scanf("%d",&y); does pretty much the same as the last 2 lines except it looks for the value for y instead of x.

6) result = x + y; that adds the values of X and Y and stores the result in the variable result.

7) printf("Here is the result %d\n",result);

return(0); that prints the result on the screen and the return(0); tells the OS that the program ended successfully.

Hope this helps,

Mr. Man

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran

Add your answer:

Earn +20 pts
Q: C programming for adding two numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp