Make a simple C program solves "There is an integer array int a [ 10 ) = (…
- User
Make a simple C program solves "There is an integer array int a [ 10 ) = ( 1,2,3,4,5,6,7,8,9,10 ), programmed to store the array in reverse order and output the result after reverse order"
- Assistant
Here is a simple C program that solves the task you described:
c#include <stdio.h> int main() { int a[10] = {1,2,3,4,5,6,7,8,9,10}; int temp; // Printing the original array printf("Original Array: "); for(int i=0; i<10; i++) { printf("%d ", a[i]); } // Reversing the array for(int i=0; i<5; i++) { temp = a[i]; a[i] = a[9-i]; a[9-i] = temp; } // Printing the reversed array printf("\nReversed Array: "); for(int i=0; i<10; i++) { printf("%d ", a[i]); } return 0; }This program first initializes an integer array
awith values(1,2,3,4,5,6,7,8,9,10). It then prints the original array and proceeds to reverse it using a temporary variable and a loop that swaps elements from both ends of the array.Finally, it prints the reversed array. The output of this program will be:
code - User
Make a simple C program that find the sum of the elements on the main diagonal of matrix a. (a[3][3)=(1,3,5,7,9,11,13,15,17)(Full
- Assistant
Here is a simple C program that finds the sum of the elements on the main diagonal of a 3x3 matrix
a:c#include <stdio.h> int main() { int a[3][3] = {{1, 3, 5}, {7, 9, 11}, {13, 15, 17}}; int sum = 0; printf("Matrix:\n"); for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { printf("%d ", a[i][j]); if(i == j) { sum += a[i][j]; } } printf("\n"); } printf("Sum of main diagonal elements: %d\n", sum); return 0; }In this program, we declare a 3x3 matrix
aand initialize it with the values(1, 3, 5, 7, 9, 11, 13, 15, 17). The program then uses two nested loops to iterate through the matrix and print its values.At the same time, it checks if the current position
(i, j)is on the main diagonal (whereiequalsj) and adds the corresponding value to the variable. - User
Write a simple C program " In singing competitions, due to the existence of certain subjective factors at the time of the referee's scoring, the scores of the singers are usually removed with a maximum score, a minimum score is removed, and the average of the remaining scores is calculated as the singer score. Write a program which function is to read the scores scored by 10 referees, remove a minimum score, remove a highest score, and calculate the average of the remaining 8 results a the singer's final score."
- Assistant
Here is a simple C program that reads the scores scored by 10 referees, removes the minimum and maximum scores, and calculates the average of the remaining 8 scores as the singer's final score:
c