[SOLVED] How can I solve this problem? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[SOLVED] How can I solve this problem?

write a function with input and output that takes an array and its size and returns how many times the maximum number is repeated

6th Sep 2018, 2:32 AM
Retag Tarek
Retag Tarek - avatar
3 Answers
+ 12
You solve it by writing a function to look at an array, find the largest number in the array, and then have the function return how many times that number is in the array. If you're asking for someone to do your homework for you, then please delete this thread. Otherwise, show your attempts.
6th Sep 2018, 3:06 AM
Fox
Fox - avatar
+ 1
CipherFox your guiding has made me solve it correctly :D #include <stdio.h> #include <stdlib.h> int h[]={2,3,8,4,8,6,7,8,8,8,8,8,8,8,8}; int y,i,j,p,x; int r=0; int size=sizeof(h)/sizeof(int); int max(int h[],int size); int main() { y=max(h,size); printf("max number is repeated for %d times",y); } int max(int h[],int size){ for (i=0;i<size;i++){ for (p=i+1;p<size;p++){ if (h[i]<h[p]){ j=h[p];} } } for (x=0;x<size;x++){ if (h[x]==j){ r=r+1; } } return r;}
6th Sep 2018, 7:11 PM
Retag Tarek
Retag Tarek - avatar
0
CipherFox i ain't looking for someone to do so, these are the ones that I can't do them so I was looking forward to having the idea of how can I do them I didn't ask for an answer I asked for how can I solve them thank you anyway
6th Sep 2018, 6:08 PM
Retag Tarek
Retag Tarek - avatar