gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
i want a code in the c language that input some numbers and it count the Repetitious…
- User
i want a code in the c language that input some numbers and it count the Repetitious numbers
- Assistant
Here is a code in C language that takes input of a set of numbers and counts the repetitious numbers:
#include <stdio.h> #define SIZE 100 int main() { int numbers[SIZE]; int frequency[SIZE]; int count = 0; printf("Enter the numbers (-1 to stop):\n"); // Input numbers int i = 0; int num; while (1) { scanf("%d", &num); if (num == -1) break; numbers[i] = num; frequency[i] = 0; i++; count++; } // Calculate frequency of numbers for (int j = 0; j < count; j++) { for (int k = 0; k < count; k++) { if (numbers[j] == numbers[k]) frequency[j]++; } } // Print repetitious numbers and their frequency printf("\nRepetitious numbers:\n"); for (int j = 0; j < count; j++) { if (frequency[j] > 1) printf("%d (Frequency: %d)\n", numbers[j], frequency[j]); } return 0; }