Facultaet_Func.c 701 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <stdio.h>
  2. int falcutaet(int num) {
  3. if (num == 1) {
  4. return 1;
  5. } else {
  6. return falcutaet(num - 1) * num;
  7. }
  8. }
  9. int main() {
  10. int num;
  11. printf("Insert a Number: ");
  12. scanf("%d", &num);
  13. int solution = falcutaet(num);
  14. FILE *file = fopen("falcutaet_2.txt", "a");
  15. if (file != NULL) {
  16. fprintf(file, "faculaet of %d is %d \n", num, solution);
  17. fclose(file);
  18. }
  19. file = fopen("falcutaet_2.txt", "r");
  20. if (file != NULL) {
  21. char buffer[1024];
  22. while (fgets(buffer, sizeof(buffer), file)) {
  23. printf("%s", buffer);
  24. }
  25. fclose(file);
  26. }
  27. return 0;
  28. }