Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int indexOf(int a, int numbers[], int size) {
- int i;
- for (i = 0; i < size; i++) {
- if (numbers[i] == a) {
- return i;
- }
- }
- return -1;
- }
- int main() {
- system("cls");
- //INPUT - @STUDENT:ADD YOUR CODE FOR INPUT HERE:
- int i, a[7];
- for(i = 0; i < 7; i++) {
- scanf("%d", &a[i]);
- }
- // Fixed Do not edit anything here.
- printf("\nOUTPUT:\n");
- //@STUDENT: WRITE YOUR OUTPUT HERE:
- int numbers[7];
- int count[7];
- int size = 0;
- int index, max, next;
- for(i = 0; i < 7; i++) {
- if (a[i] >= 100 && a[i] <= 999) { // so co 3 chu so
- index = indexOf(a[i], numbers, size);
- if (index != -1) { // tim thay ~> tang count 1
- count[index]++;
- } else {
- numbers[size] = a[i];
- count[size] = 1;
- size++;
- }
- }
- }
- if (size == 0) {
- printf("No three-digit number");
- } else {
- // tim so lan xuat hien nhieu` nhat'
- max = -1;
- for(i = 0; i < size; i++) {
- if (count[i] > max) {
- max = count[i];
- }
- }
- next = 0; // index tiep theo sau khi in so dau tien
- for(i = 0; i < size; i++) {
- if (count[i] == max) {
- printf("%d", numbers[i]);
- next = i;
- break;
- }
- }
- for(i = next+1; i < size; i++) {
- if (count[i] == max) {
- printf(" %d", numbers[i]);
- }
- }
- }
- //--FIXED PART - DO NOT EDIT ANY THINGS HERE
- printf("\n");
- system ("pause");
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement