Reputation: 1749
I wrote a simple code with dev but it does not return any thing.but with code block answer shows.what is the problem?
#include <stdio.h>
int main() {
int x,y,z;
scanf("%d%d",&x,&y);
while(z!=0){
z=x%y;
printf("%d",z);
}
return 0;
}
Upvotes: 1
Views: 129
Reputation: 106112
It invokes undefined behavior because z
is used uninitialized.
while( z!= 0)
^
|
z is uninitialized
You may get any thing either expected or unexpected result. Program may crash also. On different compilers you may get different results, which is the case here.
Upvotes: 7
Reputation: 2738
You are not able to see the output because it is closing the terminal / output window as soon as the program exits.
In code::block, they run a script to hold the output window until you press enter
.
you can have same effect by using a getch()
call at the end, before returning. this will wait for your input and give you a scope to see the result.
Besides, your program has several issues as other answers pointed out. fix them accordingly.
Upvotes: 1
Reputation: 8869
in Your Code you was Assigned z but not initialized z and you are checking while(z!=0)
so your code does not return value , fist assigned z to any value for example from scanf
.
Upvotes: 1
Reputation: 4758
Two problems I can see:
1. Value to z is un-assigned. So garbage.
2. Value of z will not change, so it's infinite loop.
Upvotes: 8