C语言查找数组里数字重复次数的方法
内容摘要
本文实例讲述了C语言查找数组里数字重复次数的方法。分享给大家供大家参考。具体如下:
#include "stdafx.h"
#include<stdio.h>
#include <iostream>
using namespace std
#include "stdafx.h"
#include<stdio.h>
#include <iostream>
using namespace std
文章正文
本文实例讲述了C语言查找数组里数字重复次数的方法。分享给大家供大家参考。具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | # 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( "输入你想查询的数:" ); 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( "共出现了 %d 次" , count ); } else { printf( "一次都没出现!" ); } system( "pause" ); return 0; } |
希望本文所述对大家的C语言程序设计有所帮助。
代码注释