327 views
1 votes
1 votes

Hi friends, In the following program when I am using '-'  in the expression "ndigit[c - '0'];" I am getting correct result but wen I am using + then I am not getting the answer, am I missing something, please answer.

 


#include <stdio.h>

int main()
{
    int c,i;
    int ndigit[10];
    
    
    for(i=0;i<10;++i)
        ndigit[i]=0;
        
        while((c=getchar())!=EOF)
        {
            
            
          if (c>='0' &&  c<='9')
          ++ndigit[c - '0'];
          
        }  
        
    printf("digits=");
    for(i=0;i<10;i++)
       printf("%d",ndigit[i]);
       
      }

Please log in or register to answer this question.

Related questions

1 votes
1 votes
1 answer
4
shaurya vardhan asked Oct 2, 2017
419 views
Verify that the expression getchar() !=EOF is 0 or 1 . here , we can take input of any character and print its Getchar value , is that what we have to do?since at the ma...