c code

  • clargest,ocurrence
  • write a c code to find largest and occurrence in array using single loop.

    WAP to find the largest number and counts the occurrence of the largest number in a dynamic array of n integers using a single loop.

    Code

    #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n, count = 0, max; printf("enter the array size\n"); scanf("%d", &n); int *arr = (int *)malloc(n * sizeof(int)); printf("enter the elements\n"); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } max = arr[0]; for (int i = 0; i < n; i++) { if (max < arr[i]) { max = arr[i]; count = 0; } if (arr[i] == max) { count++; } } printf("maximun element is : %d", max); printf("\n"); printf("ocurrence is : %d", count); return 0; }