Good day C gurus!
Write a C program that asks for 2 integer numbers (a and b) and a character in the sameline. The character is then used to define the operation to perform between the numbers aand b. Then, according to the operation selected by the user, computes and shows theresult of one of the following operations (addition/multiplication/etc....)
I tried to start with the addition first and here is my code
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;int b; char c;
scanf("%d %d ",&a,&b);
scanf("%s",&c);
printf("%d %d %s",a,b,&c);
if(c=='+')
printf("\n %d + %d = %d",a,b,a+b);
}
My code gives me very strange results!!
1
3 //Those are the two integers and symoble I inserted
+
1 0 + // the compiler has transormed my 3 to 0!!!
1+0=1 (the final result)
what's wrong??Many thanks in advance!!