Skip to content

Instantly share code, notes, and snippets.

@jezek
Last active May 24, 2018 21:39
Show Gist options
  • Save jezek/e394471b3e67d0479e413bb136f57477 to your computer and use it in GitHub Desktop.
Save jezek/e394471b3e67d0479e413bb136f57477 to your computer and use it in GitHub Desktop.
C++ program (with makefile) that writes to standart output product of 2 numbers from user input and then itself
all:
g++ main.cpp -o productWithItself
#include <stdio.h>
char *program = (char *)"#include <stdio.h>%cchar *program = (char *)%c%s%c;%cmain() {%c int a, b;%c printf(%cEnter number a: %c);%c scanf(%c%%d%c, &a);%c printf(%cEnter number b: %c);%c scanf(%c%%d%c, &b);%c printf(%cProduct of a & b = %%d%cn%c, a*b);%c printf(program, 10, 34, program, 34, 10, 10, 10, 34, 34, 10, 34, 34, 10, 34, 34, 10, 34, 34, 10, 34, 92, 34, 10, 10, 10);%c}%c";
main() {
int a, b;
printf("Enter number a: ");
scanf("%d", &a);
printf("Enter number b: ");
scanf("%d", &b);
printf("Product of a & b = %d\n", a*b);
printf(program, 10, 34, program, 34, 10, 10, 10, 34, 34, 10, 34, 34, 10, 34, 34, 10, 34, 34, 10, 34, 92, 34, 10, 10, 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment