Wednesday, 16 May 2012

Write a C program to count the occurrence of a specified number in the entered set of the number.

#include<stdio.h>
#include<stdlib.h>
int main()
{    int *p;
      int n,i,num,j=0;
    printf("\n Enter the value of n:");
    scanf("%d",&n);
    p=(int *)malloc(n*sizeof(int));
    printf("\n Enter %d numbers:",n);
    for(i=0;i<n;i++)
        scanf("%d",(p+i));
    system("clear");
    printf("\n Enter the nunmber you want to count in the given set:");
    scanf("%d",&num);
    for(i=0;i<n;i++)
    {
        if(*(p+i)==num)
            j++;
    }
    printf("\n %d occurred %d times.",num,j);
    return 0;
}

0 comments

 
© 2011-2012 ProgrammingBlue
Posts RSS Comments RSS
Back to top