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

+13 votes
asked Apr 29, 2021 by Jay Pandey (220 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;

}

5 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 (86,040 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);
0 votes
answered Sep 9, 2023 by Ananya K.J (300 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 =%.3f", division);

    return 0;

}

you can use %f as the specifier for division instead of %d which gives integer division. in case its a decimal output due to division float will fail hence better to use floating division. also if u have to improve for better division better to consider zero division error into consideration.
 

0 votes
answered Sep 10, 2023 by Ayush Thakur (140 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;
    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;

}

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