int main()
{
int firstnum ;
printf("Enter First Number :-");
scanf("%d" , &firstnum );
int numtoo ;
if((firstnum)%2 == 0)
{
int firstquo ;
int numtoo = 1 ;
int test1;
test1 = firstnum ;
do
{
firstquo = (test1)/2 ;
numtoo ++ ;
test1 = firstquo ;
} while((test1)%2 == 0);
}
else
{
numtoo = 0 ;
}
printf("%d" , numtoo);
}
What is this program?
I am making a program that calculates HCF of two user-input numbers. This is a small part of a bigger program. When I try to test this program separately I get the message Enter First Number
. When I click enter I do not get the Numtoo
value. Where did I go wrong?
6
Your issue is related to variable scope. If you declare a variable in a new scope (between {}
) it will be available to that scope only and sub-scopes.
You first declare numtoo
in the scope of the function, then later in the scope of the if
.
You should remove the second declaration in order to have numtoo
be set to the computed value.
1