The main logic for your program is:
declare integer array x[];
input lower bound, upper bound;
for( i = lower bound to upper bound )
if i (mod 7) = 0; (i.e 0 modulus mean multiple of that number)
then x[counter]=i (i.e that number)
print x[0 to max];
print count = max;
now i write this program in c , i write it in turboC compiler, to use it copy this code and paste it in turboC compiler.
//********** Code Starts From Here*****************
#include%26lt;conio.h%26gt;
#include%26lt;stdio.h%26gt;
void main(void)
{
int input_value1, input_value2, i;
int counter=0, result[50];
printf(';Enter Lower Bound:';);
scanf(';%d';,%26amp;input_value1);
printf(';Enter Upper Bound:';);
scanf(';%d';,%26amp;input_value2);
for(i=input_value1;i%26lt;input_value2;i++)
{
if(i%7==0)
{
result[counter++]=i;
}
}
printf(';The multiples of 7 in between the range %d to %d is:';,input_value1,input_value2);
for(i=0;i%26lt;counter;i++)
{
printf(';%3d,';,result[i]);
}
printf(';\n\nThe number of multiple is :%d';,counter);
getche();
clrscr();
}
//*****Code Ends Here******How to design and write a C program logic to find all the numbers that are multiples of 7?
try this:
int low, high;
// Somehow fill low, high with input
int i, n;
int result[(high-low)/7+1];
for (n = 0, i = low; i %26lt;= high; i++) if (i % 7 == 0) result[n++] = i;
// Then print out result[]
No comments:
Post a Comment