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

Submit the source code (your filename.c file) electronically and on paper as a h

ID: 3820923 • Letter: S

Question

Submit the source code (your filename.c file) electronically and on paper as a hard copy. Include copy of the results as comment lines in the completed program. All source code must be in a filename.c format. No other formats will be accepted. Phase I General Preprocessing items: Use mnemonic variables of 3 characters or more. Use void main (void) or void main in your program and leave off the return 0. Use double as the choice for all floating point values. Add heading items using as printf statement. Watch for instructions that specify a symbolic constant and assign that symbolic constant in all capital letters and using the #define. Thank you. The "xxxx" or the "(highlighted item)" in a sample output will show examples of locations that the computer program will transfer values. Phase II-General procedures: A line of information in the program should be no longer than 80 characters. All user-defined function problems should include the student's last name as part of their function name. All user- defined function written for the class must have a prototype. The user-defined functions will be located in the program after the main program. Only use local variables in the programs, no global variables. Phase III-Array names will include the student's lastname as part of the array name. Example Smith countarrayl35l; Pointers should only be used when specified as a mandatory part of the problem. Problem #1 Write a single program that reads up to 21 floating-point numbers entered at the keyboard into a one- dimensional array and has user defined functions to provide the count of both positive numbers and the negative numbers and the total of the negative and the positive numbers. The program will stop reading sets of values when the sentinel 0 is entered. The main program will print the heading, the main program will ask the user how many numbers they want to process in the array and the main will provide the option to end the program. The main program will ask the user for the values that will be placed in the array and it will call many user defined functions The 1st user defined function will count the positive numbers in the array and return that count to the main The 2nd user defined function will total the positive numbers in the array and return that total to the main The 3rd user defined function will count the negative numbers in the array and return that count to the main The 4th user defined function will total the negative numbers in the array and return that total to the main The 5th user defined function will print the positive count, the positive total, the negative count and the negative total to the screen

Explanation / Answer

#include <stdio.h>

void main(void)
{
int n,i,j,pos_c,neg_c;
double arr[21],pos_t,neg_t;
printf("How many numbers will you enter(positives & negatives) or 0");
scanf("%d",&n);
  
for(i =0; i<n; i++)
{
printf("Enter a value into array position %d :",i);
scanf("%lf",&arr[i]);
}
for(j=0;j<n;j++)
{
printf("%lf",arr[i]);
}

int pos_count(double[],int);
double pos_total(double[],int);
int neg_count(double[],int);
double neg_total(double[],int);
void print_res(int,double,int,double);
  
pos_c = pos_count(arr,n);
pos_t = pos_total(arr,n);
neg_c = neg_count(arr,n);
neg_t = neg_total(arr,n);
print_res(pos_c,pos_t,neg_c,neg_t);
}
int pos_count(double arr[], int n)
{
int count =0;
int i;
for(i=0;i<n;i++)
{
if(arr[i]>0)
count = count + 1;
}
return count;
}

double pos_total(double arr[],int n)
{
double sum = 0;
int i;
for(i =0;i<n;i++)
{
if(arr[i]>0)
{
sum = sum + arr[i];
}
}
return sum;
}

int neg_count(double arr[], int n)
{
int count =0;
int i;
for(i=0;i<n;i++)
{
if(arr[i]<0)
count = count + 1;
}
return count;
}

double neg_total(double arr[],int n)
{
double sum = 0;
int i;
for(i =0;i<n;i++)
{
if(arr[i]<0)
{
sum = sum + arr[i];
}
}
return sum;
}

void print_res(int p_c,double p_t,int n_c,double n_t)
{
printf("The sum of the %d positive values : %lf", p_c,p_t);
printf("The sum of the %d negative values : %lf", n_c,n_t);
  
}

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