Knowee
Questions
Features
Study Tools

1. Write a C program that takes n number of positive integers. Find the integer that appears the least number of times among the said integers. If there are multiple such integers, select the smallest one

Question

  1. Write a C program that takes n number of positive integers. Find the integer that appears the least number of times among the said integers. If there are multiple such integers, select the smallest one
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C program that fulfills your requirements:

#include <stdio.h>
#include <limits.h>

#define MAX 100

int main() {
    int arr[MAX], freq[MAX];
    int size, i, j, count;

    printf("Enter size of array: ");
    scanf("%d", &size);

    printf("Enter elements in array: ");
    for(i=0; i<size; i++) {
        scanf("%d", &arr[i]);
        freq[i] = -1;
    }

    for(i=0; i<size; i++) {
        count = 1;
        for(j=i+1; j<size; j++) {
            if(arr[i]==arr[j]) {
                count++;
                freq[j] = 0;
            }
        }

        if(freq[i] != 0) {
            freq[i] = count;
        }
    }

    int minCount = INT_MAX;
    int num = 0;
    for(i=0; i<size; i++) {
        if(freq[i] != 0 && freq[i] < minCount) {
            minCount = freq[i];
            num = arr[i];
        } else if(freq[i] == minCount && arr[i] < num) {
            num = arr[i];
        }
    }

    printf("The number with minimum frequency and smallest in case of a tie is: %d\n", num);

    return 0;
}

This program works by first taking the size of the array as input, then the elements of the array. It maintains a frequency array to keep track of the frequency of each element. It then iterates over the array to find the element with the minimum frequency. If there is a tie, it selects the smallest element.

This problem has been solved

Similar Questions

write a c program Find the largest number among the three numbers.

Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. Example 1:Input: n = 5Output: 10Explanation: The smallest multiple of both 5 and 2 is 10.Example 2:Input: n = 6Output: 6Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.

Problem StatementElla is developing a numeric comparison program in C that compares two numbers with different datatypes (e.g., int and long). Write a program that converts the integer to a long integer, compares the two numbers, and prints whether the first number is equal to, less than, or greater than the second number.Input format :The first line of input consists of an integer value 'n', representing the first number.The second line of input consists of a long integer value 'l', representing the second number.Output format :The output displays one of the following statements:If n is equal to l, it prints: "n and l are equal."If n is less than l, it prints: "n is less than l."If n is greater than l, it prints: "n is greater than l."Here n and l represent the first and second numbers respectively.Refer to the sample output for the formatting specifications.Code constraints :In this scenario, the test cases fall under the following constraints:-2147483647 ≤ n ≤ 2147483647-109 ≤ l ≤ 109Sample test cases :Input 1 :15050Output 1 :150 is greater than 50.Input 2 :21474836472147483647Output 2 :2147483647 and 2147483647 are equal.Input 3 :451456Output 3 :451 is less than 456.

Write a C program requesting users to enter any two positive integers. Please find the sum ofall integers between these two numbers that can be divided (divisible) by four (4).Your program should validate that both numbers are positive. If it is not so, inform the user untilhe enters a positive integer. The user can enter a larger number as the first integer and a smallernumber as the second intege

You are given two integers n and x. You have to construct an array of positive integers nums of size n where for every 0 <= i < n - 1, nums[i + 1] is greater than nums[i], and the result of the bitwise AND operation between all elements of nums is x.Return the minimum possible value of nums[n - 1]. Example 1:Input: n = 3, x = 4Output: 6Explanation:nums can be [4,5,6] and its last element is 6.Example 2:Input: n = 2, x = 7Output: 15Explanation:nums can be [7,15] and its last element is 15. Constraints:1 <= n, x <= 108

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.