bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / P044.c

P044.c (1873B)


      1 /* Write a program to input a number and check whether the
      2 number is Pronic number or not.
      3     Pronic Number: The number which is the product of two numbers
      4                    which is the product of two consecutive integer.
      5                    Ex: 20 = 4 * 5
      6 */
      7 
      8 // using boolean...
      9 /*
     10 #include <stdio.h>
     11 #include <math.h>
     12 #include <stdbool.h>
     13 
     14 int main()
     15 {
     16     int num, iterationIndex;
     17     bool isPronic = false;
     18     printf("Enter the number : ");
     19     if (scanf("%d", &num) != 1)
     20     {
     21         printf("\nYou have to enter a number, not an character or symbol.");
     22         return 1;
     23     }
     24     if (num < 1)
     25     {
     26         printf("\nOnly postive number is allowed.");
     27         return 1;
     28     }
     29     for (iterationIndex = 1; iterationIndex <= num / 2; iterationIndex++)
     30     {
     31         if (iterationIndex * (iterationIndex + 1) == num)
     32         {
     33             printf("\nInput %d is a Pronic Number.", num);
     34             isPronic = true;
     35             break;
     36         }
     37     }
     38     if(!isPronic)
     39     {
     40         printf("\nInput %d is not a Pronic Number.", num);
     41     }
     42     return 0;
     43 }
     44 */
     45 
     46 // using direct return method (more efficient and generally preferred)...
     47 
     48 #include <stdio.h>
     49 #include <math.h>
     50 
     51 int main()
     52 {
     53     int num, iterationIndex, iterationLimit;
     54     printf("Enter the number : ");
     55     if (scanf("%d", &num) != 1)
     56     {
     57         printf("\nYou have to enter a number, not an character or symbol.");
     58         return 1;
     59     }
     60     if (num < 1)
     61     {
     62         printf("\nOnly postive number is allowed.");
     63         return 1;
     64     }
     65     iterationLimit = (int)sqrt(num);
     66     for (iterationIndex = 1; iterationIndex <= iterationLimit; iterationIndex++)
     67     {
     68         if (iterationIndex * (iterationIndex + 1) == num)
     69         {
     70             printf("\nInput %d is a Pronic Number.", num);
     71             return 0;
     72         }
     73     }
     74     printf("\nInput %d is not a Pronic Number.", num);
     75     return 0;
     76 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror