visual c++ - How to find Square of a number inside a Factorial while loop in C? -
i'm trying create program not calculate factorial of number display output factorial less square of number.
these requirements: type in number between 3 9. displays in output both factorial , square. if factorial of number inserted less square of number, output string "gotcha!"
this code far. thank you
#pragma once #include <stdio.h> #define min 3 #define max 9 #define _crt_secure_no_warnings int main() { int i, fact = 1, num; printf("enter number:\n"); scanf_s("%d", &num); while (num >= min || num <= max) { (i = 1; <= num; i++) { fact = fact*i; } if (num < min || num > max) { printf("out of range. please try again.\n"); scanf_s("%d", &num); } else { printf("factorial of %d is: %d\n", num, fact); return 0; } } }
just calculate square of number multiplying itself.
square = num * num; printf("square of %d is: %d\n", num, square); if (fact < square) printf("gotcha!\n");
Comments
Post a Comment