problem: geeting message from the loop

My problem is if "printf("%d\n",begin)" never gets a number from the loop "for"
I want it to write "oops no numbers were found"
what should I do?





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
#include <stdio.h>
void main() {
	int begin,end,digit,number,i,prime,sum_digit=0,sum_prime=0;
	
	do {
		printf("please enter range<begin end> of numbers for search <begin<=end>\n");
scanf("%d%d",&begin ,&end);
	}
	while((begin>end)||(begin<10));
	for (;begin<=end;begin++) {
	number=begin;
	prime=begin;
	while (number>0)
 { 
	 digit=number%10;
number=number/10;
sum_digit+=digit;
 } 
	for (i=2;prime>2;i++) {
        
		while (prime%i==0){
			prime=prime/i;
			sum_prime+=i;
		}
	}
if (sum_prime==sum_digit)
printf("%d\n",begin);
sum_digit=0;
sum_prime=0;
	}
}



please enter range<begin end> of numbers for search <begin<=end>
44
66
Oops no numbers were found!
Last edited on
Use a flag, if remains in 0 after traverse all the range, then output your message
Topic archived. No new replies allowed.