本文實例講述了C語言查找數組里數字重復次數的方法。分享給大家供大家參考。具體如下:
#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語言程序設計有所幫助。
新聞熱點
疑難解答
圖片精選