اكتب برنامج C يقرأ سلسلة من الأعداد الصحيحة ويجد العنصر الأكثر تكرارا
- برمجة
- برمجة سي c
- 2021-05-03
- Wassim
الأجوبة
/*Write a C program to which reads a sequence of integers and find the element which occurs most frequently*/
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void) {
int in ;
int nums[101] = {0};
int i;
int max_val = 0;
printf("\nInput the terms of the sequence:\n");
while (scanf("%d", & in ) != EOF)
nums[ in ]++;
for (i = 1; i <= 100; i++) {
if (max_val < nums[i])
max_val = nums[i];
}
printf("Mode values of the said sequence in ascending order:\n");
for (i = 1; i <= 100; i++) {
if (max_val == nums[i])
printf("%d\n", i);
}
return 0;
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال