Originally Posted by

**stahta01**
Actually for this assignment i'm not allowed to use functions.. I made it work I'm just wondering if there's any way to make it run faster using just loops, break and continue.. and everything i've used there..

The hierarchy is 1. Special number (just 1)

2.Perfect number ( also we were asked specifically to work with an algorithem and not a list despite the fact there are only 4 number in that range)

3. Germain prime ( a prime number(n) so that 2*n+1 is also a prime)

4. Lower pair prime number ( a prime number (n) such that n+2 is also prime)

5. Palindrome

6. anything else

there's really just an hierarchy for the prime number ; other than that I just figured that if a number is perfect it's not prime and vice versa and the rest is how it should be.

Code:

#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>
int main(){
int firstnum = 0, secondnum = 0, remainder, sum = 0, i, j,
divisor, p, reverse,
flag1, flag2, flag3, flag4, flag5, flag6;
while (firstnum > 99999999 || firstnum < 1){ //checking to see if both numbers meet requirements
printf("Please enter the 1st int positive number (up to 8 digits):\n");
scanf("%d", &firstnum);
}
while (secondnum < firstnum + 10 || secondnum > firstnum + 150){
printf("Please enter the 2nd int positive number between %d and %d :\n", firstnum + 10, firstnum + 150);
scanf("%d", &secondnum);
}
printf("The range:\n");
while (firstnum <= secondnum){
p = firstnum, reverse = 0;
sum = 0, flag1 = 0, flag2 = 0, flag3 = 1, flag4 = 0, flag5 = 0, flag6 = 0;
while(1){
//determining if the number is a special number
if (firstnum == 1) { flag1 = 1; break; }
//determining if the number is a perfect number
for (j = 1; j < firstnum; j++){
remainder = firstnum % j;
if (remainder == 0){
sum = sum + j;
}
}
if (sum == firstnum){ flag2 = 1; break; }
//determining if the number is a prime number
if (firstnum < 2)
flag3 = 0;
if (firstnum == 2){
flag3 = 1;
}
for (int i = 2; i*i <= firstnum; i++)
{
if (firstnum%i == 0){
flag3 = 0; break;
}
}
if (flag3 == 1){
//determining if the prime number is a lower pair or a germain.
for ( i = 2, flag5=1; i*i <= (firstnum + 2); i++)
{
if ((firstnum + 2) % i == 0){
flag5 = 0; break;
}
}
for ( i = 2, flag6=1; i*i <= (2 * firstnum + 1); i++)
{
if ((2 * firstnum + 1) % i == 0){
flag6 = 0; break;
}
}}
//determining if the number is a palindrom
while (p != 0)
{
reverse = reverse * 10 + p % 10;
p /= 10;
}
if (firstnum == reverse){ flag4 = 1; break; } break;
}
if (flag1 == 1) { printf("%10d Special number.\n", firstnum); }
else if (flag2 == 1) { printf("%10d Perfect number.\n", firstnum); }
else if (flag6 == 1) { printf("%10d Germain prime number.\n", firstnum); }
else if (flag5 == 1) { printf("%10d Lower pair prime number.\n", firstnum); }
else if (flag3 == 1) { printf("%10d Prime number.\n", firstnum); }
else if (flag4 == 1) { printf("%10d Palindrom number.\n", firstnum); }
else printf("%10d\n", firstnum);
firstnum++;
}