Code:
#include <stdio.h>
int main()
{
int number=0;
char digit=0;
while(1)
{
printf("Enter the digit\n");
scanf("%c",&digit);
getchar();
printf("digit = %d\n", digit-'0');
if(digit == ' ')
{
printf("Space entered\n");
break;
}
else
{
number = number*10 + (digit-'0');
printf("The entered number is = %d\n",number);
}
}
printf("The final number is = %d ",number);
return 0;
}
Made a working version but little complex.
Enter the digit
3
digit = 3
The entered number is = 3
Enter the digit
5
digit = 5
The entered number is = 35
Enter the digit
8
digit = 8
The entered number is = 358
Enter the digit
digit = -16
Space entered
The final number is = 358
...Program finished with exit code 0
Press ENTER to exit console.