Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

n1=1 n2=2 tot=n1+n2; printf("%f"

Status
Not open for further replies.

OOzy

Programmer
Jul 24, 2000
135
0
0
SA
n1=1
n2=2
tot=n1+n2;
printf("%f",n1);
printf(" - ");
printf("%f",n2);
printf(" = ");
printf("%f",tot);

The above code should print

2 + 1 = 3

But I am using too many printfs. How can combine all the printfs into one printf
 
n1=1,
n2=2;
tot=n1+n2;

printf("%f + %f = %f",&n1,&n2,&tot);

this is better way....
Tom

 
Generaly, you can pas a pointer, why not.
But it will print value of a pointer.
 
As I see, n2, n2, tot are integers. In this case you better is:
printf("%d + %d = %d",n1,n2,tot); John Fill
1c.bmp


ivfmd@mail.md
 
Lim:
It'll print the pointers by accident. Type float is not necessarily compatible with the address of a pointer. The %p modifier would be appropriate if you wanted the address of a pointer. At any rate, that wouldn't produce the desired results.

John:
Where did you get the idea that the variables are type int?

Russ
bobbitts@hotmail.com
 
n1=1;
n2=2;
tot=n1+n2;

printf("%f + %f = %f",n1,n2,tot);

It should work.....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top