What is a nasty number? Well it is a number whose four different factors can be arranged in such a way that sum of two is equal to difference of other two. Take an example of nasty number 36. It have factors 1,2,3,4,6,9,12,18. So, we have 2+1=6-3 . So, it is a nasty number.
#include #include void main() { int i, j, yes = 0, z = 0, d = 0, v = 0, f = 0, compare, compare2, number, n = 0, ary_fac[100], ary_plus[100][100], ary_minus[100][100]; clrscr(); do { // Get the number from user to check if nasty printf("Enter any number less than 1000\n"); scanf("%d", & number); if (number > 1000) printf("Number is more than 1000\n"); } while (number > 1000); if (number = n) { // make v zero so that it is reset and we can compare all the values again with plus array v = 0; } } if (compare == compare2 && d != z && d != v && d != f && v != f && z != f && z != v) { // compare above values and make sure factors are different on both sides. yes = 1; } // if condition is satisfied then make yes=1 } } if (yes == 1) { // print if nasty number printf("yes it is a nasty no."); } else { printf("Not a nasty number"); } getch(); }