Untitled
unknown
plain_text
10 months ago
1.2 kB
4
Indexable
#include <stdio.h> #include <math.h> // Function to calculate maximum sum of exponent int max_sum_of_exponent(int A[], int B[], int N) { int i, j, temp, result = 0; // Sorting arrays A and B in non-ascending order for (i = 0; i < N-1; i++) { for (j = i+1; j < N; j++) { if (A[i] < A[j]) { temp = A[i]; A[i] = A[j]; A[j] = temp; } if (B[i] < B[j]) { temp = B[i]; B[i] = B[j]; B[j] = temp; } } } // Calculating the sum of A[i] ^ B[i] for (i = 0; i < N; i++) { result += pow(A[i], B[i]); } return result; } // Main function int main() { int N, i; printf("Enter the size of arrays A and B: "); scanf("%d", &N); int A[N], B[N]; printf("Enter the elements of array A: "); for (i = 0; i < N; i++) { scanf("%d", &A[i]); } printf("Enter the elements of array B: "); for (i = 0; i < N; i++) { scanf("%d", &B[i]); } printf("Maximum sum of exponent: %d\n", max_sum_of_exponent(A, B, N)); return 0; }
Editor is loading...
Leave a Comment