P044.c (2064B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 12 Dec 2025 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Write a program to input a number and check whether the 9 number is Pronic number or not. 10 Pronic Number: The number which is the product of two numbers 11 which is the product of two consecutive integer. 12 Ex: 20 = 4 * 5 13 */ 14 15 // using boolean... 16 /* 17 #include <stdio.h> 18 #include <math.h> 19 #include <stdbool.h> 20 21 int main() 22 { 23 int num, iterationIndex; 24 bool isPronic = false; 25 printf("Enter the number : "); 26 if (scanf("%d", &num) != 1) 27 { 28 printf("\nYou have to enter a number, not an character or symbol."); 29 return 1; 30 } 31 if (num < 1) 32 { 33 printf("\nOnly postive number is allowed."); 34 return 1; 35 } 36 for (iterationIndex = 1; iterationIndex <= num / 2; iterationIndex++) 37 { 38 if (iterationIndex * (iterationIndex + 1) == num) 39 { 40 printf("\nInput %d is a Pronic Number.", num); 41 isPronic = true; 42 break; 43 } 44 } 45 if(!isPronic) 46 { 47 printf("\nInput %d is not a Pronic Number.", num); 48 } 49 return 0; 50 } 51 */ 52 53 // using direct return method (more efficient and generally preferred)... 54 55 #include <stdio.h> 56 #include <math.h> 57 58 int main() 59 { 60 int num, iterationIndex, iterationLimit; 61 printf("Enter the number : "); 62 if (scanf("%d", &num) != 1) 63 { 64 printf("\nYou have to enter a number, not an character or symbol."); 65 return 1; 66 } 67 if (num < 1) 68 { 69 printf("\nOnly postive number is allowed."); 70 return 1; 71 } 72 iterationLimit = (int)sqrt(num); 73 for (iterationIndex = 1; iterationIndex <= iterationLimit; iterationIndex++) 74 { 75 if (iterationIndex * (iterationIndex + 1) == num) 76 { 77 printf("\nInput %d is a Pronic Number.", num); 78 return 0; 79 } 80 } 81 printf("\nInput %d is not a Pronic Number.", num); 82 return 0; 83 }