HW 9/19/2018


1

#include<stdio.h>
#include <stdlib.h>

int roll();
int main() {

unsigned int i, n, seed,die1,die2,sum,Count=0;
double percent;

printf("Enter seed value: ");
scanf("%d", &seed);

srand(seed);

printf("Enter number of rolls of Dice: ");
scanf("%d", &n);

for(i=0; i<n; i++){
die1 = roll();
die2 = roll();
sum = die1+die2;
if (sum==8){
Count++;
}
 
}

percent=(Count)*100/n;

printf("Number of rolls: %d\n", n);
printf("Percent with sum of 8 : %4.2f %\n", percent);
return 0;
}

int roll(){

return rand()%(1) ;
}

2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define e 2.718282
#define pi 3.141593


int main(void) {
int n_val;
int n_val_fact(int n_val);
printf("Enter n:\n");
scanf("%d",&n_val);
while (n_val<0)
{
printf("The n value must not be negative \n");
printf("Enter the value of n:\n");
scanf("%d",&n_val);
}
printf("n! stiring approximation value about %i is %i \n",n_val,n_val_fact(n_val));

return 0;
}


int n_val_fact(int n_val)
{
if (n_val==0)
{return 0;}
else
{return (int)((sqrt(2*pi*n_val))*pow((n_val/e),n_val)+0.5);}}

Comments

Popular posts from this blog