program to print multiples of 5 using do while loop
Answers
Answered by
3
class multiple
{
void display()
{
longint sum=0,i,n; clrscr();
printf("\n Please Give The Value of N: ");
scanf("%ld",&n);
for(i=1;i<=n;i++) { printf("\n 5 * %ld = %ld",i,5*i);
}
getch();
}
OUTPUT
N: 5 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
{
void display()
{
longint sum=0,i,n; clrscr();
printf("\n Please Give The Value of N: ");
scanf("%ld",&n);
for(i=1;i<=n;i++) { printf("\n 5 * %ld = %ld",i,5*i);
}
getch();
}
OUTPUT
N: 5 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25
diyab0416:
what is getch?
Answered by
2
The program given here prints the first 10 multiples of 5. You can modify it accordingly.
int multiplesFound = 0; //track how many multiples found
int currentNumber = 1; //start checking at 1
do {
if(currentNumber % 5 == 0) {
multiplesFound++;
System.out.println("Found multiple of 5: " + currentNumber);
}
currentNumber++;
} while(multiplesFound<10);
Hope it helps :)
Similar questions