i am new in c . i have made the code in C++.its working fine. the only problem i face i got error in printf statment.
please tell me how can i change cout statement into printf

#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	
	int x=0;


	for(int i=0;i<=6;i++)
	{
          cout<<x<<"  "<< pow (2,x)<<endl;
          x++;
         }	
	return 0;
}

For each object you print using cout, figure out the type and put it in a format string. String literals go into the format string as is, and in order. In your case, the types are int (for x) and double (for the return type of pow), so you would have something like this:

/* cout<<x<<" "<< pow (2,x)<<endl; */
printf ( "%d %f\n", x, pow ( 2, x ) );

Simply printing a newline is sufficient to flush in C, so no extra work is necessary (unlike with endl in C++).

p.s. If that's the only line you change, you'll have more errors when compiling as C.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.