only one semicolon!!!

good day all,

I'm a new member
and I have a c++ challenge and need your help

the problem is

write a complete c++ program that read number and print it's square
note: you can use only one semicolon!!

I hope to have the answer as quickly as possible.

thanks for all

best regards
Only one semicolon in the entire program is quite difficult, the problem could mean that you should use << and >> stream operators.

If you really have to use just one semicolon try something like this:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

#define sc ;
//sc will be replaced with a ';' by the preprocessor

int main()
{
    std::cout << "No semicolons here" sc
    return 0 sc
}
Last edited on
mmmmmmm
that to seem funny

thanks alot
if I use it correctly, the result should be like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

#define sc ;

int main ()

{
     int x sc

      std :: cout << "Enter number \n"  sc
      std :: cin >> x sc
      std :: cout << "The result = : " << x * x << std :: endl sc

      return 0 sc
}


isn't that

thanks alot for your help

regards ^_^
Last edited on
This seems to be a pretty flawed challenge with many possible solutions.

I'd say the biggest issue is that they all depend on the program before pre-processing. iostream has plenty of semi-colons in it when expanded, as would the rest of your code. Another way that works on the same general loophole to do this is

1
2
3
4
5
6
7
8
9
10
11
// another file
#include <iostream>
using namespace std;

int cheat() {
  int x;
  cout << "x=" << endl;
  cin >> x;
  cout  << "x*x = " << x * x << endl;
  return 0;
}


1
2
3
4
5
6
// the "real" file
#include "file1.cpp" //should really be a header/cpp pair in real programming, but we don't need that here

int main(int argc, char** argv) {
  return cheat();
}
Last edited on
hhhh;

thank you very much,
good way !!
Here's another way that is much less "cheaty," but requires C (not C++) for the lack of a return statement (and type of main).

1
2
3
4
5
6
#include <stdio.h>

main(int argc, char** argv) 
{
  int x, a = printf("x=\n"), b = scanf("%d", &x), c = printf("x*x=%d\n", x*x);
}
It's legal for main to have a return type, but not a return statement (although it's generally advised that it has both).


Here's another way that is much less "cheaty," but requires C (not C++) for the lack of a return statement (and type of main).


#include <stdio.h>

main(int argc, char** argv)
{
int x, a = printf("x=\n"), b = scanf("%d", &x), c = printf("x*x=%d\n", x*x);
}




really nice
I like that
it will work in c++ if we write it like this

1
2
3
4
5
6
7
8
9

#include <stdio.h>

int main(int argc, char** argv) 
{
  int x, a = printf("x=\n"), b = scanf("%d", &x), c = printf("x*x=%d\n", x*x);
}



just add the function main type "int main"

good work
thanks for your help

I want to ask if you have any problems like this
I challenged my friend
and I want problems to ask him
can you help ??

regards

Last edited on
I prefer to do it like this?

1
2
3
4
5
6
7
#include <stdio.h>
#include <stdlib.h>

int main(int argc,char*argv[])
{
      cout<<(gets(argv[1]),atoi(argv[1])*atoi(argv[1]));
}


No cheats, I suppose. Only the use of gets(), and argv[1] as a storage can raise eyebrows.. :)
Last edited on
anyway,
I have another solution
lets try something like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14

#include <iostream>


void main()
{

int i;
if (std::cout<<"Enter the number:\n") {}
if (std::cin>>i) {}
if (std::cout<<"the result is: "<<i * i) {}

}
hahahahaha... great minds on work.. :)
Topic archived. No new replies allowed.