Showing posts with label no of occurence of 2 in number range. Show all posts
Showing posts with label no of occurence of 2 in number range. Show all posts

5.17.2013

Count digit repetition in number range

Q. Write a C program to count the no. of occurences of n's in a given number range.

For example:
random numbers : 45,78,2,65,489,6,2,6,55,9
find out how many times the digit 2 repeat?
2's digit repeat 2 times.

Ans.

/*c program to count the no. of occurences of n's in numbers range*/
#include<stdio.h>
int main()
{
 int arr[10],i,num,r,s,c=0;
 for(i=1; i<=10; i++)
 {
  printf("Enter %d number : ",i);
  scanf("%d", &arr[i]);
 }
 printf("\nEnter search number : ");
 scanf("%d", &s);