View Feed
group-icon
Coffee Room
Discuss anything here - everything that you wish to discuss with fellow engineers.
12915 Members
Join this group to post and comment.
Paramita
Paramita • Dec 27, 2012

Please check this code

i have a question. my compiler is not working.thats why i am using online free compiler. so i cant understand properly is my code right or not. so please help me someone. i am posting my code:

#include

main()
{
int numb_one;
int numb_two;
int ans=numb_one+numb_two;

printf("Put no one:\n");
scanf("%d",numb_one);
printf("Put no two:");
scanf("%d",numb_two);
scanf("%d",ans);
getchar();
return 0;

}
grsalvi
grsalvi • Dec 27, 2012
You have not used ampersand (&) in scanf.
And in 3rd last line ,though code the statement is correct,but i believe you actually want to show the answer.
In that case the 3rd last statement is : printf("%d",ans);
[Prototype]
[Prototype] • Dec 27, 2012
As well you're doing the addition operation even before assigning proper values to your variable. You've to first assign the values to your variables and then perform operation on them.
Beginner
Beginner • Dec 27, 2012
In order to read a value from the keyboard, you will need to specify an address.
For example, say you need to store some value in the variable x, you'll have to specify
scanf ("%d",&x);
when this statement is executed, whatever the input is given, it is stored into x.
To be more clear when to enter a value, you can specify a printf statement before the scanf as follows
printf("enter a value for x");
This will prompt you to enter a value for x. Hope you got it..
i think there are some online programming sources where you cannot give values from keyboard at the run time. in that cases ,you should remove the scanf statements and directly initialize the values to the variable.
rahul69
rahul69 • Dec 27, 2012
Also, U r adding the values without initializing, the statement:
 int ans=numb_one+numb_two;
should be after u have scanned both numbers, otherwise ur "ans" will not have sum of two numbers.😀

Share this content on your social channels -