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.

answer out put is wrong

+6 votes
asked Apr 29, 2021 by Jay Pandey (180 points)
#include<stdio.h>
int main(){
    int a, b, c, d, e, f, sum, sub, multiplication, divsion;

    printf("input 1st no:\n");
    scanf("%d" , &a);

    printf("input 2nd no:\n");
    scanf("%d", &b);

    c=a+b, sum;
    d=a-b, sub;
    e=a*b, multiplication;
    f=a/b, divsion;

    printf("\naddition is =%d", &c);
    printf("\nsub is =%d", &d);
    printf("\nmultiplication is =%d", &e);
    printf("\ndivsion is =%d", &f);

    return 0;

}

3 Answers

+1 vote
answered May 2, 2021 by Han-ma-bookie (360 points)
#include<stdio.h>
int main(){
    int a, b, c, d, e, f;

    printf("input 1st no:\n");
    scanf("%d" , &a);

    printf("input 2nd no:\n");
    scanf("%d", &b);

    c=a+b;
    d=a-b;
    e=a*b;
    f=a/b;

    printf("\naddition is =%d", c);
    printf("\nsub is =%d", d);
    printf("\nmultiplication is =%d", e);
    printf("\ndivsion is =%d", f);

    return 0;

}
+1 vote
answered May 2, 2021 by Sans Nom (160 points)
#include<stdio.h>
int main(){
    int a, b, sum, sub, multiplication, division;

    printf("input 1st no:\n");
    scanf("%d" , &a);

    printf("input 2nd no:\n");
    scanf("%d", &b);

    sum=a+b;
    sub=a-b;
    multiplication=a*b;
    division=a/b;

    printf("\naddition is =%d", sum);
    printf("\nsub is =%d", sub);
    printf("\nmultiplication is =%d", multiplication);
    printf("\ndivsion is =%d", division);

    return 0;

}

its best that we step by step go through the changes together.
CONTACT  nelby#5120 on discord for more information.
(or email [email protected]) <3
+1 vote
answered May 3, 2021 by Peter Minarik (55,660 points)

For scanf you need to provide the memory address where the value should be stored, (You did this correctly)

However, for printf, you need to provide the actual value (not the memory address of the value). (This is where you erred).

Your code correctly would be as below (removed the & -- memory address of -- operator):

    printf("\naddition is =%d", c);
    printf("\nsub is =%d", d);
    printf("\nmultiplication is =%d", e);
    printf("\ndivsion is =%d", f);
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.
...