Author

Topic: じじじ C-Programming Mania 0.001฿ Prize じじじ (Read 811 times)

full member
Activity: 278
Merit: 104
#include
#include
#include
void alex()
{
printf("30");
getch();
exit(0) ;
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}

explanation :

1. "exit(exit_code)  " this is not right. and moreover you need to include the proper header file for them to work. and the header file in this case is
 "stdlib.h"

2. In exit code you need to have an integer value.

3. getch() in alex() function because in order to see the result we need to hold the screen before it exits and that is why I have included "getch"  function in alex() .





ahh....good!
you are correct ! your method is different for what i thought. anyways congrats, let me know your BTC address.

thank you

Oh shoot! lol don't know what the fuck was i doing, btw if you're still seeing this here's my address: 1GKbp7H3xJpWwbTzLJBKcqxm7KXZLGTNjQ

thanks buddy!!
legendary
Activity: 1652
Merit: 1016
Hehe, funny task.
Code:
void alex()
{
printf(" 0\r");
}
It simply prints a space for the digit 3 that will be printed later in main() and also prints the zero that is missing to form output "30". "\r" returns carriage to the beginning of the line so that the digit 3 is printed instead of the space.

That doesn't work in Linux console. The carriage return erases the previous characters.
Likewise, alternatively using the "\b" backspace does the same erasing.


If you replace the getch() function, which is from conio.h, by an equivalent function getchar() from stdio.h, you get the result as stated even in Linux console.

At least I didn't need to #include another header file like the accepted solution. Wink

Just tried it, it works now. Well done.

Never used conio.h anyway, the library isn't on my system.


newbie
Activity: 36
Merit: 0
Hehe, funny task.
Code:
void alex()
{
printf(" 0\r");
}
It simply prints a space for the digit 3 that will be printed later in main() and also prints the zero that is missing to form output "30". "\r" returns carriage to the beginning of the line so that the digit 3 is printed instead of the space.

That doesn't work in Linux console. The carriage return erases the previous characters.
Likewise, alternatively using the "\b" backspace does the same erasing.


If you replace the getch() function, which is from conio.h, by an equivalent function getchar() from stdio.h, you get the result as stated even in Linux console.

At least I didn't need to #include another header file like the accepted solution. Wink
sr. member
Activity: 402
Merit: 250
#include
#include
#include
void alex()
{
printf("30");
getch();
exit(0) ;
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}

explanation :

1. "exit(exit_code)  " this is not right. and moreover you need to include the proper header file for them to work. and the header file in this case is
 "stdlib.h"

2. In exit code you need to have an integer value.

3. getch() in alex() function because in order to see the result we need to hold the screen before it exits and that is why I have included "getch"  function in alex() .





ahh....good!
you are correct ! your method is different for what i thought. anyways congrats, let me know your BTC address.

thank you
legendary
Activity: 1652
Merit: 1016
Hehe, funny task.
Code:
void alex()
{
printf(" 0\r");
}
It simply prints a space for the digit 3 that will be printed later in main() and also prints the zero that is missing to form output "30". "\r" returns carriage to the beginning of the line so that the digit 3 is printed instead of the space.

That doesn't work in Linux console. The carriage return erases the previous characters.
Likewise, alternatively using the "\b" backspace does the same erasing.

newbie
Activity: 36
Merit: 0
Hehe, funny task.
Code:
void alex()
{
printf(" 0\r");
}
It simply prints a space for the digit 3 that will be printed later in main() and also prints the zero that is missing to form output "30". "\r" returns carriage to the beginning of the line so that the digit 3 is printed instead of the space.
full member
Activity: 278
Merit: 104
#include
#include
#include
void alex()
{
printf("30");
getch();
exit(0) ;
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}

explanation :

1. "exit(exit_code)  " this is not right. and moreover you need to include the proper header file for them to work. and the header file in this case is
 "stdlib.h"

2. In exit code you need to have an integer value.

3. getch() in alex() function because in order to see the result we need to hold the screen before it exits and that is why I have included "getch"  function in alex() .



sr. member
Activity: 402
Merit: 250

#include
#include
void alex()
{
printf("30");
exit(exit_code) 
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}


Cheesy

did you ever ran this program?? or just giving answer.
what is
Quote
exit(exit_code) 
?
legendary
Activity: 1722
Merit: 1000
Satoshi is rolling in his grave. #bitcoin

#include
#include
void alex()
{
printf("30");
exit(exit_code) 
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}


Cheesy
legendary
Activity: 1302
Merit: 1005
New Decentralized Nuclear Hobbit
j=30 means that the value of j must print 30 not string "j=30"

lol jk. I know what you meant. Grin
New answer.



even if you make j to static then also there is no use of it because after the function alex() , you are assigning j=3 , think carefully its a booby trap.
i will be glad if anyone solves it and same you will feel.

Sad I was hoping static will make the value unchangeable throughout the code.
sr. member
Activity: 402
Merit: 250
i think you guys are talking the question wrong i dont want your answer to be like this ->

but the required result has to be like this ->
j=30 means that the value of j must print 30 not string "j=30"

Will this work?

#include
#include
void alex()
{
static int j = 8;
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}

even if you make j to static then also there is no use of it because after the function alex() , you are assigning j=3 , think carefully its a booby trap.
i will be glad if anyone solves it and same you will feel.
legendary
Activity: 1302
Merit: 1005
New Decentralized Nuclear Hobbit
Will this work?

#include
#include
void alex()
{
static int j = 30;
}
void main()
{
   int  j=0;
   j = 2;
   for (int i = 1; i<10; i++)
   {
      if (i % 2 == 0)
      {
         j++;
      }
   }
   alex();
   j = 3;
   printf("%d", j);
   getch();
}
sr. member
Activity: 402
Merit: 250
yes , j will always be 3 if you check by inserting break point. but the question is you need to print 30 by configuring the alex().
the question is valid and very conceptual.



no , i have assigned the value to j two times , anyways it is to confuse you and at last again i have assigned value to j..all is to confuse the programmer.

the similar question was posted in google code jam

Interesting.

I wanted to be sure it is really intended to be j. My knowledge in C++ is very limited. But since you said "easy question" I had to try Grin

yeah , i will be glad if you can solve it , the concept i am talking about is not just limited to c/c++ but is is also applicable in c#,f# not sure about java.

the question is very simple yet people often ignore their first lesson.

Good luck!
legendary
Activity: 1302
Merit: 1005
New Decentralized Nuclear Hobbit
yes , j will always be 3 if you check by inserting break point. but the question is you need to print 30 by configuring the alex().
the question is valid and very conceptual.



no , i have assigned the value to j two times , anyways it is to confuse you and at last again i have assigned value to j..all is to confuse the programmer.

the similar question was posted in google code jam

Interesting.

I wanted to be sure it is really intended to be j. My knowledge in C++ is very limited. But since you said "easy question" I had to try Grin
sr. member
Activity: 402
Merit: 250


I just read
Quote
The definition void main() is not and never has been C++, nor has it even been C.



Won't j always be 3?

   alex();
   j = 3;
   printf("%d", j);
   getch();


yes , j will always be 3 if you check by inserting break point. but the question is you need to print 30 by configuring the alex().
the question is valid and very conceptual.

Code:
void main()
{
int  j=0;
j = 2;

Do you mean int i=0 instead of j?
[/quote]

no , i have assigned the value to j two times , anyways it is to confuse you and at last again i have assigned value to j..all is to confuse the programmer.

the similar question was posted in google code jam
legendary
Activity: 1302
Merit: 1005
New Decentralized Nuclear Hobbit
Code:
void main()
{
int  j=0;
j = 2;

Do you mean int i=0 instead of j?

I just read
Quote
The definition void main() is not and never has been C++, nor has it even been C.



Won't j always be 3?

   alex();
   j = 3;
   printf("%d", j);
   getch();
sr. member
Activity: 402
Merit: 250
Well , I want to start some coding topics here as i belong to former. I will post some easy questions which you guys need to answer , the time allotted will be 24 hrs , you can give multiple answers but the console output must be the same what is required in question.

Code:

#include
#include
void alex()
{
//your code here
}
void main()
{
int  j=0;
j = 2;
for (int i = 1; i<10; i++)
{
if (i % 2 == 0)
{
j++;
}
}
alex();
j = 3;
printf("%d", j);
getch();
}


do whatever you want with alex() but dont touch the code of main() , i just want you to print j=30 at last.

will see if anyone can solve this or all guys here are just working as signature workers.


Hint: The program contains some dummy loop and you just need to focus on what you want and unnecessary overheads , ignore them.

the answer must be with explanation with full description , i dont want just code(no stackoverflow) , in case you are not able to convince me you will miss the prize.
Good Luck!
Jump to: