Answer the question
In order to leave comments, you need to log in
How to work with arrays in C?
Please help with the task: If the elements located after the minimum are ordered in descending order, then find the sum of the elements located before the minimum and divide it by the maximum.
Here is my code:
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
int a[100];
int i, j, n, min, max, ind, sum;
double ch;
char flag = 0;
sum = 0;
printf("Vvedite razmer vectora n=");
scanf("%d",&n);
for (i=0; i<n; i++)
{
printf("a[%d]=",i);
scanf("%d", &a[i]);
}
min = a[0];
ind = 0;
for (i = 0; i < n; i++)
if (min > a[i])
{
min = a[i];
ind=i;
}
printf("\n Min element = %d", min);
printf("\n Index min elementa = %d \n", ind);
max = a[0];
for (i = 0; i < n; i++)
if (max < a[i]) max = a[i];
printf("\n Max element = %d \n", max);
for(i=ind+2; i<n; i++)
{
if(a[i-1] < a[i])
{
flag = 1;
break;
}
if(!flag) sum = sum + a[i];
}
ch = min / max;
printf("\n Summa elementov do min = %d \n", sum);
printf("\n Chastnoe min / max = %d \n", ch);
for (i=0; i<n; i++)
printf("%2d", a[i]);
}
Answer the question
In order to leave comments, you need to log in
find the sum of the elements located up to the minimumand where do you have it?
And dividing the minimum element by the maximum counts incorrectly, 0 is always written thereand what do you think the result of an integer division of a by b should be equal to, with b greater than a ?
That's it, hang up, I've already done everything.
Here is the code if anyone needs it:
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
int main()
{
int a[100];
int i, j, n, min, max, ind, sum;
float ch;
char flag;
printf("Vvedite razmer vectora n=");
scanf("%d",&n);
for (i=0; i<n; i++)
{
printf("a[%d]=",i);
scanf("%d", &a[i]);
}
min = a[0];
max = min;
ind = 0;
for (i = 0; i < n; i++)
if (min > a[i])
{
min = a[i];
ind=i;
}
if (max < a[i]) max = a[i];
printf("\n Min element = %d", min);
printf("\n Index min elementa = %d \n", ind);
max = a[0];
for (i = 0; i < n; i++)
if (max < a[i]) max = a[i];
printf("\n Max element = %d \n", max);
flag = 0;
for(i=ind+2; i<n; i++)
{
if(a[i-1] < a[i])
{
flag = 1;
break;
}
}
sum = 0 ;
if(flag==0)
for(i=0; i<ind; i++)
sum = sum + a[i];
ch = (float)min / max;
printf("\n Summa elementov do min = %d \n", sum);
printf("\n Chastnoe min / max = %f \n", ch);
for (i=0; i<n; i++)
printf("%2d", a[i]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question