4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in descending order. Perform sorting by passing array to a function mySort(array, sortingOrder). Then multiply both the arrays returned from function, using metric multiplication technique in main. Print result in metric format.



4-Take two sets of 5 numbers from user in two arrays. Sort array 1 in ascending and array 2 in desce..

Answer / Tejpal Sagar

In C, you can implement this as follows:n```cnvoid mySort(int arr[], int size, char order); // Define the sorting function prototype here.nnint main() {n int arr1[5], arr2[5]; // Initialize two arrays of 5 elements each.n get_input(arr1, arr2); // Get input from user for both arrays.n mySort(arr1, 5, 'a'); // Sort array1 in ascending order.n mySort(arr2, 5, 'd'); // Sort array2 in descending order.n multiply_and_print(arr1, arr2); // Multiply and print the sorted arrays.n return 0;n}nnvoid mySort(int arr[], int size, char order) {n // Implement sorting logic here based on provided input order (a for ascending, d for descending).n}nn// Get input from user for both arrays.nvoid get_input(int arr1[5], int arr2[5]) {n int i;n for (i = 0; i < 5; i++) {n printf("Enter element %d of array 1:
", i + 1); // Prompt user for input.n scanf("%d
", &arr1[i]);n printf("Enter element %d of array 2:
", i + 1); // Prompt user for input again for array2.n scanf("%d
", &arr2[i]);n }n}nn// Multiply and print both arrays.nvoid multiply_and_print(int arr1[5], int arr2[5]) {n int product = 0;n int i;n for (i = 0; i < 5; i++) {n product += arr1[i] * arr2[i]; // Metric multiplication.n }n printf("The product is %d cm^3
", product);n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

Write programs for String Reversal & Palindrome check

1 Answers   TISL,


Explain what is the benefit of using an enum rather than a #define constant?

1 Answers  


What are the features of c languages?

1 Answers  


How can I list all of the predefined identifiers?

1 Answers  


Write a program that receives as input a number omaadel-n-print, four digits.

0 Answers  


#define f(x) main() { printf("\n%d",f(2+2)); }

5 Answers  


Is malloc memset faster than calloc?

1 Answers  


Tell me with an example the self-referential structure?

1 Answers  


study the code: #include<stdio.h> void main() { const int a=100; int *p; p=&a; (*p)++; printf("a=%dn(*p)=%dn",a,*p); } What is printed? A)100,101 B)100,100 C)101,101 D)None of the above

15 Answers   Accenture, TCS,


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

0 Answers   L&T,


How do you print an address?

1 Answers   TCS,


different between overloading and overriding

3 Answers  


Categories