Help Needed in C.

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Help Needed in C.

Post by uvasarker » Sun Jan 06, 2013 5:25 am

Which one is better? And why?
Please, help............

Code 1:::

Code: Select all

#include <cstdio>

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0 ; i<n ; i++ ){
        printf("Help Needed.\n");
    }
    return 0;
}

Code 2:::

Code: Select all

#include <cstdio>
#define IN ( {int _T; scanf("%d",&_T); _T;} )
#define loop(ini, lim, inc) for(int i=ini ; i<lim ; i+=inc)

int main()
{
    int n=IN;
    loop(0,n,1){
        printf("Help Needed.\n");
    }
    return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Help Needed in C.

Post by brianfry713 » Mon Jan 07, 2013 3:04 am

I think code 1 is easier to read.
Check input and AC output for thousands of problems on uDebug!

uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: Help Needed in C.

Post by uvasarker » Mon Jan 07, 2013 3:41 pm

Hmm,
Guru
Any difference with execution time?

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Help Needed in C.

Post by brianfry713 » Mon Jan 07, 2013 10:18 pm

Not much difference in runtime.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Algorithms”