4
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by Narue
2

Can anyone tell me the Coding for:

[ATTACH]18596[/ATTACH]


Help me!!!

I'd be happy to give you complete code so you don't have to do any work at all!

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define f(x) ((x)>0?((x)*((x)+1)/2):0)
#define g(x) (((int)sqrt(8.0*(x)+1)-1)/2)

int main(int c, char **v)
{
    if (c>1)
        for (c=0;c<f(atoi(v[1]));c++)printf("%s%*s%d",c==f(g(c))?"\n":" ",c==f(g(c))?atoi(v[1])-g(c)-1:0,"",g(c)+1);
    return !putchar('\n');
}

There's no need to thank me, I'm here to help. :)

Votes + Comments
Punishment.. LOL (:
0

That's disgusting. You could've made it worse by changing all variable names to a multitude of underscores. That would obfuscate it even more ;)

0

I didn't really want to go full IOCCC style obfuscation. This way it looks ugly, but otherwise reasonable. One might expect to see some of the newbies on Daniweb come up with a program that appears similar at a glance. You'd wonder what the defines are for in such a simple nested loop exercise, and shake your head at the unconventional formatting, but only after a closer look will the fun stuff shine through. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.