Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROBLEM 1
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main(void)
- {
- srand(time(NULL));
- /** LOCAL DECLARATIONS GO HERE ***/
- int flips = 1000;
- int i;
- int numHeads = 0;
- int numTails = 0;
- int HorT = 0; //Random number
- /** FOR LOOP GOES HERE ***/
- for(i = 0; i < flips; i++){
- HorT = rand() % 2;
- if (HorT == 1){
- numHeads++;
- }
- else{
- numTails++;
- }
- }
- printf("Heads = %d\n", numHeads);
- printf("Tails = %d\n", numTails);
- return 0;
- }//end main
- PROBLEM 2
- /*
- * Compose a program using a for loop that will determine the
- * factorial of a user supplied number.
- * BY: Larry Snedden
- */
- #include <stdio.h>
- int main(void)
- {
- //Local declarations
- int factorial = 1;
- int i;
- int n = 0;
- //Local statements get inputs, process then output
- printf("Enter in a number for factorial: ");
- scanf("%d", &n);
- for(i = 1; i <= n; i++ )
- {
- factorial = factorial * i;
- }
- //Output results
- printf("Factorial of %d! = %d\n", n, factorial);
- return 0;
- }//end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement