C language to find the number of repeats in an array

  • 2020-04-02 03:09:55
  • OfStack

This example shows how the C language finds the number of repeats in an array. Share with you for your reference. The details are as follows:


#include "stdafx.h"
#include<stdio.h>
#include <iostream> 
using namespace std;
int main()
{
  int myarray[10]={4,3,7,4,8,7,9,4,3,6};
  printf(" Enter the number you want to query: ");
  int number=0;
  cin>>number;
  int count=0;
  for(int i=0;i<sizeof(myarray);i++)
  {
    if(number==myarray[i])
    {
      count++;
    }
  }
  if(count!=0)
  {
    printf(" A total of the  %d  time ",count);
  }
  else
  {
    printf(" Not once! ");
  }
  system("pause");
  return 0;
}

Hope that the article described in the C programming language for you to help.


Related articles: