Please check this code

Paramita

Paramita

@paramita-hFZ3JD Oct 26, 2024
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<stdio.h>

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;

}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • grsalvi

    grsalvi

    @grsalvi-7IhIh1 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]

    @prototype-G9Gn5k 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

    @beginner-5onRAV 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..
  • ashwin sarangula

    ashwin sarangula

    @ashwin-sarangula-Eb5r0N Dec 27, 2012

    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

    @rahul69-97fAOs 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.😀