#include <stdio.h> #include <stdlib.h> #include <time.h> /*The goal of this prog
ID: 3619158 • Letter: #
Question
#include <stdio.h> #include <stdlib.h> #include <time.h>/*The goal of this program is to create an array and fill itwith numbers created by a random number generator using structs. We alsohave to pick out the largest number in both sets in the array while also usingstructs.*/
typedef struct { int a; int b; } pie;
void print_array(pie array[],int size); void largest_a(pie array[],int size); void largest_b(pie array[],int size);
int main() { pie array[20]; int size = sizeof(array)/sizeof(array[0]); printf("size of array is %d ",size); srand ( time(NULL) );
print_array(array,size); largest_a(array,size); largest_b(array,size);
return 0; }
void print_array(pie array[],int size) { int i; for(i = 0; i < size; i++) { array[i].a = rand() % 100 + 1; array[i].b = rand() % 100 + 1; } for(i = 0;i < size; i++) { printf("array[%d].a = %d ",i,array[i].a); printf("array[%d].b = %d ",i,array[i].b); } }
void largest_a(pie array[],int size) { int max = array[0].a; int i; for(i = 1; i < size;i++) { if(array[i].a > max) { max = array[i].a; } } printf("The largest a value is %d ",max); }
void largest_b(pie array[],int size) { int max = array[0].b; int i; for(i = 1; i < size;i++) { if(array[i].b > max) { max = array[i].b; } } printf("The largest b value is %d ",max); }
#include <stdio.h> #include <stdlib.h> #include <time.h>
/*The goal of this program is to create an array and fill itwith numbers created by a random number generator using structs. We alsohave to pick out the largest number in both sets in the array while also usingstructs.*/
typedef struct { int a; int b; } pie;
void print_array(pie array[],int size); void largest_a(pie array[],int size); void largest_b(pie array[],int size);
int main() { pie array[20]; int size = sizeof(array)/sizeof(array[0]); printf("size of array is %d ",size); srand ( time(NULL) );
print_array(array,size); largest_a(array,size); largest_b(array,size);
return 0; }
void print_array(pie array[],int size) { int i; for(i = 0; i < size; i++) { array[i].a = rand() % 100 + 1; array[i].b = rand() % 100 + 1; } for(i = 0;i < size; i++) { printf("array[%d].a = %d ",i,array[i].a); printf("array[%d].b = %d ",i,array[i].b); } }
void largest_a(pie array[],int size) { int max = array[0].a; int i; for(i = 1; i < size;i++) { if(array[i].a > max) { max = array[i].a; } } printf("The largest a value is %d ",max); }
void largest_b(pie array[],int size) { int max = array[0].b; int i; for(i = 1; i < size;i++) { if(array[i].b > max) { max = array[i].b; } } printf("The largest b value is %d ",max); }
Explanation / Answer
please rate - thanks you weren't specific about your problem code with sort #include #include #include #include /*The goal of this program is to create an array and fill it withnumbers created by a random number generator using structs. We also have topick out the largest number in both sets in the array while also usingstructs.*/ typedef struct { int a; int b; } pie; void sort_a(pie array[],int size); void sort_b(pie array[],int size); void print(pie array[],int size); void print_array(pie array[],int size); void largest_a(pie array[],int size); void largest_b(pie array[],int size); int main() { pie array[20]; int size = sizeof(array)/sizeof(array[0]); printf("size of array is %d ",size); srand ( time(NULL) ); print_array(array,size); largest_a(array,size); largest_b(array,size); sort_a(array,size); printf(" sorted by a "); print(array,size); sort_b(array,size); printf(" sorted by b "); print(array,size); getch(); return 0; } void sort_a(pie array[],int size) {int i,j; pie t; for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.