I am writing a program to add two numbers. But instead of adding, the result is some thing else like z=0.0000 or z=4209163 while my two numbers to be added are 10 and 20. Please help.
I am writing a program to add two numbers. But instead of adding, the result is some thing else like z=0.0000 or z=4209163 while my two numbers to be added are 10 and 20. Please help.
Show your program.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
My program is:
Code:#include<stdio.h> #include<conio.h> void main() { float n1,n2,ans; printf("Enter the First number\n"); scanf("%f",&n1); printf("Enter the Second number\n"); scanf("%f",&n2); ans=n1 + n2; printf("Your Answer is -: %.3f",&ans); }
Drop the & from the printf.
main returns int, not void.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.