I need the pseudocode for this c program source code. #include<stdio.h> void pri
ID: 3759310 • Letter: I
Question
I need the pseudocode for this c program source code.
#include<stdio.h>
void printarray(int array[], int asize){
int i;
for(i = 0; i < asize;i++)
printf("%d", array[i]);
printf(" ");
}
int sum(int array[], int asize){
int result = 0;
int i = 0;
for(i=0;i < asize;i++){
result = result + array[i];
}
return result;
}
int swap( int* pA,int*pB){
int result = 0;
if(*pA > pB){
int tamp = *pA;
*pA = *pB;
*pB = tamp;
result = 1;
}
return result;
}
int sort_1pass(int array[], int asize){
int result = 0;
int i;
for(i=0;i < asize-1;i++){
result = result + swap(&array[i], &array[i+1]);
}
return result;
}
void sort(int array[],int asize){
int result = 1;
while(result!=0){
result = 0;
result = sort_1pass(array, asize);
printarray(array, asize);
}
}
int main(){
int array[] ={8,1,8,2,0,3,1,9,8};
int size = 9;
printarray(array, size);
printf("The sum is%d ", sum(array, size));
sort(array, size);
printf("The median is: %d ", array[size / 2]);
printf("The average is %0.2lf ",(double)sum(array, size)/size);
}
Explanation / Answer
Pseudocode:
1. Declare and initialize an array of type int with some values name it array.
2. declare an int variable size which represents the total number of elements present in an array.
3. Define a function printarray with parameters of an int array and int variable.Implement this function for printing the array.
4. Call the above implemented function.
5. Define a function sum with parameters of an int array and int variable.Implement this function for calculating the sum of elemets present in array.
6. Call the above implemented function and print the result.
7. Implement a sort function which will sort the array.
8. Call above implemented function for sorting the array.
9. Print the middle element of an array as a median of array.
10. Calculate the average of the array by caluclating the sum and dividing the sum by size and print the result.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.