Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 7th, 2012  |  syntax: None  |  size: 3.56 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <stdbool.h>
  5.  
  6. int CountPrimes(int primes,int *pPrimesout);
  7. void DisplayReport(int primes,int factorial,int leapyear,int primesout,int factorialout,int leapyearout);
  8. int GetFactorial(int factorial, int *pFactorialout);
  9. bool IsLeapYear(int leapyear, int *pLeapyearout);
  10. bool IsPrime(int *isprime, int *pPrimeout);
  11. void PerformOperations(int primes, int factorial, int leapyear, int *pPrimesout, int *pFactorialout, int *pLeapyearout, int *pPrimecount);
  12. bool ValidateInput(int *pPrimes, int *pFactorial, int *pLeapyear);
  13. bool WithinRange(int input, int minRange, int maxRange);
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17.         //int argv[3];
  18.         int primes;
  19.         int factorial;
  20.         int leapyear;
  21.         int primesout;
  22.         int factorialout;
  23.         int leapyearout;
  24.         int primecount;
  25.         ValidateInput(&primes, &factorial, &leapyear);
  26.         PerformOperations(primes, factorial, leapyear, &primesout, &factorialout, &leapyearout, &primecount);
  27. //      DisplayReport(primes, factorial, leapyear, primesout, factorialout, leapyearout);
  28.        
  29.         system("pause");       
  30.         return 0;
  31. }
  32.  
  33. bool ValidateInput(int *pPrimes, int *pFactorial, int *pLeapyear)
  34. {
  35.         int flag=1;
  36.        
  37.         printf("Project 3: ");
  38.         scanf("%d %d %d", pPrimes, pFactorial, pLeapyear);
  39.         printf("%d %d %d", *pPrimes, *pFactorial, *pLeapyear);
  40.        
  41.         if(flag=1)
  42.         {
  43.                 flag = WithinRange(*pPrimes, 1, 1000);
  44.                 if(flag = 1)
  45.                 {
  46.                         flag = WithinRange(*pFactorial, 1, 12);
  47.                         if(flag = 1)
  48.                         {
  49.                                 flag = WithinRange(*pLeapyear, 1, 4000);
  50.                                 if(flag = 1)
  51.                                 {
  52.                                         flag = 1;
  53.                                 }
  54.                                 else
  55.                                 printf("Data is invalid.");
  56.                         }
  57.                         else
  58.                         printf("Data is invalid.");
  59.                        
  60.                 }
  61.                 else
  62.                 printf("Data is invalid.");
  63.         }
  64. return flag;
  65. }//end ValidateInput
  66.  
  67. bool WithinRange(int input, int minrange, int maxrange)
  68. {
  69.         int valid = 1;
  70.         if(input < minrange || input > maxrange)
  71.         {
  72.                 printf("The value is out of range. \n");
  73.                 valid = 0;
  74.         }
  75.         return valid;
  76. }//end WithinRange
  77.  
  78. void PerformOperations(int primes, int factorial, int leapyear, int *pPrimesout, int *pFactorialout, int *pLeapyearout, int *pPrimecount)
  79. {      
  80.         IsPrime(primes, &pPrimesout);
  81.         //GetFactorial(factorial, &pFactorialout);
  82.         //IsLeapYear(leapyear, &pLeapyearout);
  83.         //CountPrimes(primes, &pPrimecount);
  84.         return 1;
  85. }
  86.  
  87. bool IsPrime(int *isprime, int *pPrimeout)
  88. {
  89. int x;
  90. int primetest=1;
  91. printf("test%d",isprime);
  92.  
  93. for(x=2; x<=floor(sqrt(*isprime)); x++)
  94.         {
  95.         if(*isprime%x==0)
  96.                 {
  97.         primetest = 0;  //number is not prime
  98.                 }
  99.         }
  100.         printf("%d",primetest);
  101.         return primetest;
  102. }
  103. /*
  104. int GetFactorial(int factorial, int *pFactorialout)
  105. {
  106.         int x = factorial;
  107.         int c;
  108.         int answer;
  109.         for(c = 1, c<=x, c++)
  110.         {
  111.         answer = x*c;
  112.         }
  113.         return answer;
  114. }
  115.  
  116. bool IsLeapYear(int leapyear, int *pLeapyearout)
  117. {
  118.         if(leapyear%400 == 0 || (leapyear%100 != 0 && leapyear%4 == 0))
  119.     {
  120.         pLeapyearout=1;
  121.     }
  122.     else
  123.     {
  124.         pLeapyearout=0;
  125.     }
  126.         return pLeapyearout;
  127. }
  128.  
  129. int CountPrimes(int primes,int *pPrimesout)
  130. {
  131.         int num;
  132.        
  133.         for(num=1;num<=primes;num++)
  134.         {
  135.         pPrimesout=num;
  136.         }
  137.         return pPrimesout;
  138. }
  139.  
  140. for(x = 3; x == primeIn; x++)
  141. {
  142.        
  143.         if(x%2 == 0)
  144.         {
  145.         break;
  146.         }
  147.         else
  148.         {
  149.                 x = IsPrime(x);
  150.                 if(x == 1)
  151.                 {
  152.                 *pPrimeCount++;
  153.                 }
  154.         }
  155. }
  156.  
  157. }
  158.  
  159. void DisplayReport(int primes,int factorial,int leapyear,int primesout,int factorialout,int leapyearout)
  160. {
  161.         printf("Jason Gutel\n");
  162.         printf("Project 3 - Simple Operations Program\n\n");
  163.         printf("Operation Results:\n");
  164.         printf("------------------\n\n");
  165.         printf("Exactly %d prime numbers exist between 0 and %d", primesout, primes);
  166.         printf("The value of %d! is %d", factorial, factorialout);
  167.         if(leapyearout=1)
  168.         {
  169.         printf("The year %d is a leap year",leapyear);
  170.         }      
  171.         else
  172.         printf("The year %d is not a leap year",leapyear);
  173. }*/