Code:
/******************************************************************************/
/******** This program is combines from Project #2 thru #5 to find the *******/
/********** values that multiples of 7 or actually contain a digit 7 **********/
/******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define MSIZE 500
#define DSIZE 500
int main()
{
int mul7[MSIZE]; //array multiples by 7
int dig7[DSIZE]; //array contain a digit 7
int n; //number
int sr; //starting range
int er; //engding range
int c7; //values that multiples by 7
int d7; //values that contain a digit 7
double mavg; //average of values multiples by 7
double davg; //average of values contain a digit 7
printf("Enter start and end range values: ");
while((n = scanf ("%i %i", &sr, &er)) == 2)
{
if (sr < 0 || er > 999 || sr > er)
printf("Range value out of range\n");
else
{
c7 = fmul7(sr, er, mul7, MSIZE);
d7 = fdig7(sr, er, dig7, DSIZE);
mavg = calcavg(mul7, c7);
davg = calcavg(dig7, d7);
outresults(sr, er, mul7, MSIZE, dig7, DSIZE, c7, d7, mavg, davg);
printf("Enter start and end rage values: ");
}
}
if (n != EOF)
printf("Input error occurred in scanf\n");
system("PAUSE");
return 0;
}
/******************************************************************************/
/***** This little subprogram is about finding the values multiples by 7 ******/
/******************************************************************************/
int fmul7(int str, int endr, int mul7[], int m7size)
{
int ndx; //index number
int rem; //remain number
int i; //count number
i = 0;
for (ndx = str; ndx <= endr; ndx++)
{
rem = ndx % 7;
if (rem == 0)
{
mul7[m7size] = ndx;
i = i + 1;
}
}
return 0;
}
/******************************************************************************/
/**** this little subprogram is about finding the values contain a digit 7 ****/
/******************************************************************************/
int fdig7(int str, int endr, int dig7[], int d7size)
{
int q1; //first digit
int q2; //second digit
int q3; //third digit
int rem1; //remainder
int num; //number
int c7; //count number
c7 = 0;
for(num = str; num <= endr; num++)
{
q1 = num / 100;
rem1 = num - (q1 * 100);
q2 = rem1 / 10;
q3 = rem1 - (q1 * 10);
if (q1 == 7 || q2 == 7 || q3 == 7)
{
dig7[d7size] = num;
c7++;
}
}
return 0;
}
/******************************************************************************/
/** This little subprogram is about finding the avarage of all number *********/
/******************************************************************************/
double calcavg(int md7[], int cntmd7)
{
int ndx; //index number
int sum; //total sum
double avg; //total avarage
sum = 0;
avg = 0.0;
for (ndx = 0; ndx < cntmd7; ndx++)
sum = sum + md7[ndx];
if (cntmd7 == 0)
printf("Average divisor is zero - skip division \n");
else
avg = (double) sum / ndx;
return 0;
}
/******************************************************************************/
/************ This little subprogram is about output information **************/
/******************************************************************************/
void outresults (int sr, int er, int m7[], int szm7, int d7[], int szd7, int cm7,
int cd7, double mav, double dav)
{
int i;
printf("Start Range = %i End Range = %i\n", sr, er);
printf("Multiple of 7 count is: %i\n", cm7);
printf("Number having digit 7 count is: %i\n", cd7);
printf("Multiple of 7 values are: \n");
for (i = 0; i < cm7; i++)
printf("%i\n", m7[i]);
printf("Values having digit 7 are: \n");
for (i = 0; i < cd7; i++)
printf("%i\n", d7[i]);
printf("Multiple of 7 average is: %0.2lf\n", mav);
printf("Values having digit 7 average is: %0.2lf\n", dav);
}
I got error "coflicting types for 'calcavg', and conflicting types for 'outresults' "