Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed i have this code in c that dose not work

+7 votes
asked Jan 21, 2023 by Parth sharma (200 points)
closed Jan 31, 2023 by Admin
# include<stdio.h>

 int main(){   

 int a;   

 int b;     printf("the value of a\n");

     scanf("%d/n", &a);

      printf( "the value of b \n" );

    scanf("%d\n"& b );   

  printf("the sum of two numbers is %d", a + b);

     return 0;

}
closed with the note: answered

11 Answers

+5 votes
answered Jan 22, 2023 by Zaydiscool777 (360 points)

I can see a few reasons why your code doesn't work.

  1. the newline symbol is typed incorrectly on line 5, but not elsewhere.

  2. a newline isn't supposed to be used when scanning

  3. there is no comma on line 7 seperating the string and the address

0 votes
answered Jan 22, 2023 by vivek chavan (140 points)
This code wont work, it has many mistakes and even many syntax are missing.

the correct code is :-

#include <stdio.h>

int main() {
    int a, b, result;
    
    printf("Enter first  number : ");
    scanf("%d", &a);
    
    printf("Enter second number : ");
    scanf("%d", &b);
    
    //add two numbers
    result = a + b;
    printf("Sum : %d\n", result);
    
    return 0;
}

try this one
0 votes
answered Jan 22, 2023 by Kirti Pandey (140 points)
#include<stdio.h>

void main()

{

int num1,num2,result;

printf("\n Enter the first number");

scanf("%d", &num1);

printf("\n Enter the second number");

scanf("%d", &num2):

result=num1+num2;

printf("The addition of %d and %d=%d", num1,num2,result);

getch();

}
0 votes
answered Jan 22, 2023 by SS21CO054 Abdulrehman Ansari (140 points)
# include<stdio.h>

 int main(){   

 int a;   

 int b;     
      printf("the value of a\n");

     scanf(" \n %d", &a);

      printf( "the value of b \n" );

    scanf("%d",& b );   

  printf("\n the sum of two numbers is: %d ", a + b);

     return 0;

}
0 votes
answered Jan 22, 2023 by NIRAJ RAJ (140 points)
#include<stdio.h>

int main()

{

 int a,b;

 printf("the value of a\n");

scanf("%d/n",&a);

printf("the value of b\n");

scanf("%d\n",&b);

printf("the sum of two number is %d",a+b);

return 0:

}
0 votes
answered Jan 23, 2023 by Veera Goud (230 points)
# include<stdio.h>

 int main()
 {   
 int a,b;
printf("the value of a and b\n");
 scanf("%d %d",&a,&b);
printf("the sum of two numbers is %d", a + b);
 return 0;
 }

the reason your code doesn't work is there are syntax errors in your code and as well as there are a lot unnecessary extra lines written in your code, Always try to code in fewer steps so that when there are errors you easily identify them and correct them, if there are a lot of line you have to spend a lot of time searching for the mistake and correcting it. Hope this helps you
0 votes
answered Jan 23, 2023 by ronak raj (140 points)
in second scanf there must be a comma .

code:::

#include<stdio.h>

 int main(){   

 int a;   
 int b;    
 printf("the value of a\n");
 scanf("%d", &a);
 printf( "the value of b \n" );
 scanf("%d",&b);   
 printf("the sum of two numbers is %d",a+b);
 return 0;
}
0 votes
answered Jan 24, 2023 by Uttam J (140 points)

scanf("%d/n", &b );   

copy paste this in ur code ... you have missed a comma and used backslash instead of /

0 votes
answered Jan 30, 2023 by Sachin sah (160 points)

# include<stdio.h>

 int main()
 {   

 int a;   

 int b;     
 printf("the value of a");

     scanf("%d", &a);

      printf( "the value of b" );

    scanf("%d",& b );   

  printf("the sum of two numbers is %d", a + b);

     return 0;
}

NOW U CAN HAVE A SOLN.....

0 votes
answered Jan 31, 2023 by Sandeep Yadav (140 points)
error is scanf("%d\n",&b);
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...