1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
/*MAIN PROGRAM*/
#include <stdio.h>
#include <stdlib.h>
#define MSIZE 500
#define DSIZE 500
int main()
/*Main*/
{
int mul7[MSIZE]; /*Values that are multiples of 7*/
int dig7[DSIZE]; /*Values that have 7 in them*/
int n; /*Entered Values*/
int sr; /*Start Range*/
int er; /*End Range*/
int c7; /*Multiples of 7*/
int d7; /*Digits with 7*/
double mavg; /*Average of Multiples*/
double davg; /*Average of Digits*/
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);
Here mavg=calcavg(mul7,c7);
davg=calcavg(dig7,d7);
Here outresults(sr,er,mul7,MSIZE,dig7,DSIZE,c7,d7,mavg,davg);
printf("Enter start and end range values:");
}
}
if(n !=EOF)
printf("Input error occurred in scanf\n");
system("PAUSE");
return 0;
}
/*M7*/
int fmul7(int str, int endr, int mul7[MSIZE], int m7size)
{
int ndx;
int rem;
int i;
i=0;
for(ndx=0; ndx<=MSIZE; ndx=ndx++)
{
rem=ndx%7;
if(rem==i)
{
mul7[i]= rem;
i = i+1;
}
}
return i;
}
/*D7*/
int fdig7(int str, int endr,int dig7[DSIZE], int d7size)
{
int q1;
int num;
int c7;
int q2;
int q3;
int rem1;
c7=0;
for(num=str; num<=endr; num++)
{
q1=num/100;
rem1=num-(q1*100);
q2=rem1/10;
q3=rem1-(q2*10);
if(q1==7||q2==7||q3==7)
{
dig7[c7]=num;
c7++;
}
}
return c7;
}
/*Avg*/
double calcavg(int md7[], int cntmd7)
Here {
int ndx;
int sum;
double avg;
sum=0;
avg=0.0;
for(ndx=0;ndx<cntmd7;ndx++)
sum=sum+md7[ndx];
if(cntmd7==0)
printf("Average divisior is zero - skip division \n");
else
avg=(double)sum/cntmd7;
return avg;
}
/*Output*/
void outresults(int sr, int er, int m7[], int szm7, int d7[], int szd7, int cm7, int cd7, double mav, double dav)
and Here {
int i;
printf("Start Range=%i End Range=%i \n", &sr,&er);
printf("Multiple of 7 count is: %i \n", &cm7);
printf("Number of Digits 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("5i\n", &d7[i]);
printf("Multiples of 7 average is : %0.21f\n", &dav);
}
|