sprockets brown shoe Purple Dinosaurs Yellow Duck tangerines Duplicator Wizard Gound Hog Lair metalic mobius shape
sprockets
Recent Posts | Unread Content
Jump to content
Hash, Inc. - Animation:Master

Recommended Posts

  • Hash Fellow
Posted

A programming guru tests your eye for bugs in C.

Bonus: Can you spot HIS mistake?
 

 

  • 1 month later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Maybe it is fixed from this ? :)

#include <stdio.h>

int sum = 0;
int num = 0;

int main()
{
    
   for (int num = 0; num < 5; sum = num++)
   {
       sum = sum + sum;
   }
    
    printf("%d\n", sum);

    return 0;
}

 

Posted

But better maybe he means that to fix :

#include <stdio.h>

int sum = 0;
int num = 0;

int main()
{
    
   for (int num=0; num < 5; num++)
   {
       sum += (num+2)/2;
   }
    
    printf("%d\n", sum);

    return 0;
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...