首页 > 编程 > C++ > 正文

C语言查找数组里数字重复次数的方法

2020-05-23 14:18:08
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要介绍了C语言查找数组里数字重复次数的方法,涉及C语言针对数组的遍历与判断技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了C语言查找数组里数字重复次数的方法。分享给大家供大家参考。具体如下:

 

 
  1. #include "stdafx.h" 
  2. #include<stdio.h> 
  3. #include <iostream>  
  4. using namespace std; 
  5. int main() 
  6. { 
  7. int myarray[10]={4,3,7,4,8,7,9,4,3,6}; 
  8. printf("输入你想查询的数:"); 
  9. int number=0; 
  10. cin>>number; 
  11. int count=0; 
  12. for(int i=0;i<sizeof(myarray);i++) 
  13. { 
  14. if(number==myarray[i]) 
  15. { 
  16. count++; 
  17. } 
  18. } 
  19. if(count!=0) 
  20. { 
  21. printf("共出现了 %d 次",count); 
  22. } 
  23. else 
  24. { 
  25. printf("一次都没出现!"); 
  26. } 
  27. system("pause"); 
  28. return 0; 
  29. } 

希望本文所述对大家的C语言程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表