Fun with C++

Take the following code:

int i, n = 20;
for (i=0; i< n; i--)
{
cout << "x" << endl;
}

by changing only ONE character in the above code, meaning you cannot change 20 to 31, because you will have changed two characters, you can change 20 to 21, because you only changed the 0, do the following:

find 3 ways to make the above code print x 20 times (by changing only one character).



1) Write one line of code to swap the contents two variables without using a temp variable.

2) Write a program to print 1-100 and backward without using loops.

3)Write a C++ program to print out "Hello world" without using any ';'


For 2)

#include
void count(int n, int max)
{
std::cout <<<" "; if(n < n =" 100;">
int main(){
double a,b;
std::cout <<"Input a,b separated by space : "; std::cin >> a >>b;
a-=b=(a+=b)-b; //one line swapping +/-
std::cout <<"a= "<< b=" ">
}

3)
#include
int main(){
double a,b;
std::cout <<"Input a,b separated by space : "; std::cin >> a >>b;
a-=b=(a+=b)-b; //one line swapping +/-
std::cout <<"a= "<< b=" ">
}

1)
void main()
{
if(printf("Hello World!\n")){}
}

0 comments: