اكتب برنامج بلغة C لإيجاد أقصى n - m بحيث تكون المصفوفة [n]> المصفوفة [m] من مصفوفة معطاة []
- برمجة
- برمجة سي c
- 2021-05-05
- Wassim
الأجوبة
/*Write a program in C to find the maximum n – m such that array[n] > array[m] from a given array[]*/
#include <stdio.h>
int findMaxDiffercence(int arr1[], int ar_size)
{
int mandndiff = -1;
int m, n;
for (m = 0; m < ar_size; ++m)
{
for (n = ar_size-1; n > m; --n)
{
if(arr1[n] > arr1[m] && mandndiff < (n - m))
{
printf("m = %d, n = %d, arr1[m] = %d arr1[n] = %d difference = %d\n",m,n,arr1[m],arr1[n],n-m);
mandndiff = n - m;
}
}
}
return mandndiff;
}
int main()
{
int arr1[] = {7, 5, 8, 2, 3, 2, 4, 2, 1, 0};
int n = sizeof(arr1)/sizeof(arr1[0]);
int i;
//------------- print original array ------------------
printf("The given array is: \n");
for(i = 0; i < n; i++)
{
printf("%d ", arr1[i]);
}
printf("\n");
//-----------------------------------------------------------
int mandndiff = findMaxDiffercence(arr1, n);
printf("\nThe maximum differcences between two position of array index is: %d", mandndiff);
getchar();
return 0;
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال