Example : A C++ program to use setprecision() formatted method.
# include <iostream>
# include <iomanip>
using namespace std;
	
int main ()
{
	float x,y,z;
	x = 17;
	y = 3;
	z = x/y;
	cout << setprecision(1) << z << endl;
	cout << setprecision(2) << z << endl;
	cout << setprecision(3) << z << endl;
	cout << setprecision(4) << z << endl;
	cout << setprecision(5) << z << endl;
	return 0;
}
Output :
6
5.7
5.67
5.667
5.6667

Example : A C++ program to print a message without main and cout object.

# include <iostream>
using namespace std;  
#define x main   
int x() 
{ 
    if (cout<<"Hello Codershelpline Viewers") 
	{	
        } 
    return 0;
}

---------  OR  ----------
# include <iostream>
using namespace std;  
#define x cout<<"Hello Codershelpline Viewers"   
int main() 
{ 
    if (x) 
	{	
        } 
    return 0;
}

---------  OR  ----------
# include <iostream>
using namespace std;  
int main() 
{ 
    if (std::cout <<"Hello Codershelpline Viewers")  
    { 
    } 
}
 
---------  OR  ----------
# include <iostream>
using namespace std;  
int main() 
{ 
    switch (cout<<"Hello Codershelpline Viewers")  
    { 
    } 
}
 
---------  OR  ----------
# include <iostream>
using namespace std; 
int main() 
{ 
    while (!(std::cout << "Hello Codershelpline")) 
    { }   
}

---------  OR  ----------
# include <iostream>
using namespace std; 
int main() 
{ 
    for (; !(std::cout << "Hello Codershelpline") ; ) 
    { } 
}

Loading

Categories: C++

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.