Question

Write a program in C to count the frequency of the selected element of an array. Sample input/output dialogue

Sample input/output dialogue: 

Enter array element limit: 5 

Enter 5 elements in the array: 1 1 2 3 1 

Enter element to search for frequency : 1 

Result is : 1 occurs 3 times

2 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

CODE:

 

#include <stdio.h>

int main()

{

    int n;

    printf("Enter array element limit: ");

    scanf("%d", &n);

    int arr[n];

    printf("Enter %d element in the array: ", n);

    for (int i = 0; i < n; i++)

    {

        scanf("%d", arr[i]);

    }

    printf("Enter element to search for frequency: ");

    int k;

    scanf("%d", &k);

    int count = 0;

    for (int i = 0; i < n; i++)

    {

        if (arr[i] == k)

        {

            count++;

        }

    }

    printf("Result is: %d occurs %d times", k, count);

}

 

 

 

OUTPUT:

image.png

answered by: Mystrious Tahin
Add a comment
Know the answer?
Add Answer to:
Write a program in C to count the frequency of the selected element of an array. Sample input/output dialogue
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • in C language Write a program to find the element of an array, which occurs maximum...

    in C language Write a program to find the element of an array, which occurs maximum number of times and its count. The program should accept the array elements as input from the user and print out the most occurring element along with its count. Hint: array size is 5. For example: Enter array elements (array size 5): 22321 Output: Max occurring element: 2. count: 3

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • Please do in C and only use stdio.h. Write a program that reads n integers into...

    Please do in C and only use stdio.h. Write a program that reads n integers into an array, then prints on a separate line the value of each distinct element along with the number of times it occurs. The values should be printed in ascending order. Turn in your code and input/result together. Suppose, for example, that you input the values -7 3 3 -7 5 5 3 as the elements of your array. Then your program should print -7...

  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • In need this in C language! Write a program that declares a 40 element array of...

    In need this in C language! Write a program that declares a 40 element array of type double. Initialize the array so that: the first 10 elements are equal to the square of the index variable the next 10 each elements is equal to three times the index variable the next 10 each element is equal to the sum of an element in the first 10 + an element in the second 10 the last 10 each element is equal...

  • Java code INNER PRODUCT 4E Input Standard input Output Standard output Topic Array & Array Processing!...

    Java code INNER PRODUCT 4E Input Standard input Output Standard output Topic Array & Array Processing! Problem Description The inner product (also known as the dot product or scalar product) of the elements of set A and the elements of set B of size is defined as the sum of the products of corresponding terms. For example, given set A as the array (2, 3, 4, 5, 6, 7, 8, 9; and set B as 6,5, 4, 3, 2, 7,...

  • Create a program that counts how many times a number is included in an array. To...

    Create a program that counts how many times a number is included in an array. To create the array ask for 10 values (as integers) and then ask for the number that should be checked for. Then print the number of times the requested number appears in the array (see below). Please comment your code as you go along. Hint: You may need 2 for loops for this, one to create your array and one to check the values. Enter...

  • Write a java program: Create a method fillRandom() that accepts an array of int as input...

    Write a java program: Create a method fillRandom() that accepts an array of int as input and populates it with random numbers in the range -999 to 1000 Explicitly store zero in index [0] and 900 in index [1]. (0 and 900 will be used as search keys) Create a method DisplayLastInts() that accepts an array of int as input and displays the last hundred elements to the screen in rows of 10 elements. Format the output so the 10...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT