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.

i have this code in c that dose not work

+2 votes
asked 5 days ago by Parth sharma (150 points)
# 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;

}

8 Answers

+4 votes
answered 5 days ago by Zaydiscool777 (340 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 5 days ago 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 4 days ago 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 4 days ago 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 4 days ago 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 3 days ago by Veera Goud (190 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 3 days ago 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 2 days ago 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 /

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.
...