Write a function to read a sequence of character digits and convert it to decima
ID: 3929636 • Letter: W
Question
Explanation / Answer
#include <stdio.h>
int getnum()
{
int ans=0;
char c;
printf("Enter a number(a space to end):");
//scanf("%c",&c);
int count=0;
while(1)
{
scanf("%c",&c);
//printf("%c ",c);
if(count==0 && c==' ')
{
continue;
}
if(c==' ')
{
break;
}
ans = ans*10+(c-'0');
count++;
}
return ans;
}
int main()
{
printf("The value was: %d ",getnum());
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.