Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this project you need to summarize an array. Summary of an (data) array means

ID: 3759219 • Letter: I

Question

In this project you need to summarize an array. Summary of an (data) array means that printing all the items and quantity of a specific items found in the array. The summary of the array should be kept in another 1D array. Summary array should keep the items of data arrays in order. For instance, we are given an array with 10 items, 5 3 19 5 4 3 7 3 3 5 then summary of these array should be another array of 3 4 4 1 5 3 7 1 19 1 Notice that in the summary array [2*n] shows the item found in the data array and [2*n+1] shows the quantity of [2*n+1], such as [0]=3, and [1] =4, how many times 3 found in the data array. Note that the size of summary array is not known.

Explanation / Answer

#include <stdio.h>

int sum_array(int a[], int num_elements);
void print_array(int a[], int num_elements);

void main(void)
{
   int a[10] = {5, 3, 19, 5, 4, 3, 7, 3, 3, 5};
   int b[10];
int sum;
int i;
   printf(" Array: ");

   for(i=0; i<10; i++)
   {
   if(a[i]>a[i+1])
{
b[i]=a[i];
}
else
{
b[i]=a[i+1];
}
}
print_array(b, 10);

   sum = sum_array(b, 10);
   printf("The sum is %d ", sum);
}

int sum_array(int b[], int num_elements)
{
   int i, sum=0,count=0;
   for (i=0; i<num_elements; i++)
   {
sum = sum + b[i];
   if(b[i]==3)
{ count++;}}
printf("no of 3's in array is%d",count);
   return(sum);
}

void print_array(int b[], int num_elements)
{
   int i;
   for(i=0; i<num_elements; i++)
   {
   printf("%d ", b[i]);
   }
   printf(" ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote