اكتب برنامج C يقرأ سلسلة من الأعداد الصحيحة ويجد العنصر الأكثر تكرارا

  • برمجة
  • برمجة سي c

اكتب برنامج C يقرأ سلسلة من الأعداد الصحيحة ويجد العنصر الأكثر تكرارا

مثال عن الخرج المتوقع :

 

Input the terms of the sequence:
5
2
4
6
8
10
^Z
Mode values of the said sequence in ascending order:
2
4
5
6
8
10

الأجوبة

/*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;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...