Программа виснет когда попадается не совершенное число.
#include stdio.h
int main()
{
int m, n, i, count1 = 0, count2 = 0, a, b, f = 0;
scanf("%d%d",&m,&n);
for (i = m; i <=n; i++)
{
a = i;
while(a>0)
{
while(b != 1)
{b = a % 2;
if (b == 1)
{if(a == i)
{f = 1;}
break;}
a = a / 2;
count1++;}
if(f == 0)
{while(b != 0)
{b = a % 2;
if(b == 0)
{f = 1;
if(a == 0)
{f = 0;}
break;}
a = a / 2;
count2++;}
}}
if (f == 0 && count1 == count2 - 1)
{printf("%d ",i);}
f = 0;
count1 = 0;
count2 = 0;
}
}
#include stdio.h
int main()
{
int m, n, i, count1 = 0, count2 = 0, a, b, f = 0;
scanf("%d%d",&m,&n);
for (i = m; i <=n; i++)
{
a = i;
while(a>0)
{
while(b != 1)
{b = a % 2;
if (b == 1)
{if(a == i)
{f = 1;}
break;}
a = a / 2;
count1++;}
if(f == 0)
{while(b != 0)
{b = a % 2;
if(b == 0)
{f = 1;
if(a == 0)
{f = 0;}
break;}
a = a / 2;
count2++;}
}}
if (f == 0 && count1 == count2 - 1)
{printf("%d ",i);}
f = 0;
count1 = 0;
count2 = 0;
}
}