Problem with changing of elements' locations


Joined
Oct 18, 2022
Messages
1
Reaction score
0
Good day, guys. Can you please help with the problem? The point is that the greatest element of an array should change its place with the first one. I pointed out an array and the maximum element in an array. Can you please say, what should I do next?

#include <stdio.h>
#include <cmath>
int n, i, arr[100], sum;
int main()
{

scanf("%d", &n);
sum = 0;
for (i = 0; i < n; i++)
scanf("%d", &arr);

for (i = 0; i < n; i++)
sum = sum + arr;

int arrmax = -100;
for (i = 0; i < n; i++)
if (arr > arrmax) arrmax = arr;

for (i = 0; i < n; i++)
arr[1] = arrmax;

printf("%d", arr);
return 0;

}

P. S: I wrote a[1] = arrmax, but it doesn't make any sense
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top