|
问题。。。。 无法进入 Calculation... 高手们帮忙看一看
p/s: 红色部分:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
long int factorial(int n); // prototype
void factorial_calculator (void) ; // prototype
void binomial (void); //prototype
long int ncr( int n , int r ); //phototype
main(void){ //start main
int choice ;
char end = 'Y';
printf("Hi, welcome to binomial equation calculator\n\n");
while ( choice != 1 || choice != 2 ){
printf(
"Select a choice\n"
" 1) = factoria calculator\n"
" 2) = binomial expression\n\n"
"choice = ");
scanf("%d" , &choice);
switch(choice){ //start switch
case 1:
factorial_calculator();
break;
case 2: // leave blank 1st
binomial();
break;
default:
printf("Invalid Input - Please try again\n\n");
} // end while
} // end switch
}// end main
void factorial_calculator (void) {
int n;
printf(
"Enter number Of a "
"a! = ");
scanf("%d" , &n ) ;
printf("%d! = %d\n\n" , n , factorial(n));
}// end factorial calculator
long int factorial (int n) {
if (n == 1)
return(1) ;
else
return( n * factorial(n - 1 ));
} // end factorial
void binomial (void) {
/* binomial variable*/
int choice = 0 , n , count = 0;
float a , b;
double x , y , z;
/*end variable*/
while ( choice != 1 || choice != 2 ) { //while 1
printf(
"\n\nWhich case?\n"
"1) (a+bX)^n\n"
"2) (aX+b)^n\n"
"case = "); //end printf
scanf("%d", &choice);
printf("\n");
switch (choice) { //switch 1
case 1:
printf(
"(a+bX)^n\n"
"a = "); //end printf
scanf(" %f", &a);
printf("b = ");
scanf(" %f" ,&b);
printf("n = ");
scanf(" %d" ,&n);
for (count = 0 ;count <= n; ++count ) { // for
//calculation
x = pow(a , (n - count) );
y = pow(b , count );
z = ncr(n , count);
if (count < n ) printf("%dX^5d + " ,x * y * z , count );
else if (count == n ) printf("%dX^5d ", x * y * z , count );
} // end for
break;
case 2:
printf(
"(aX+b)^n\n"
"a = "); //end printf
scanf(" %f", &a);
printf("b = ");
scanf(" %f" ,&b);
printf("n = ");
scanf(" %d" ,&n);
while (count <= n) {
x = pow(a , (n - count));
y = pow(b , count );
z = ncr(n , count);
if (count < n ) printf("%dX^%d + " ,z * x * y , count );
else if (count == n ) printf("%dX^%d " ,z * x * y , count );
count++ ;
} // end for
break;
default:
printf("invalid input - Please Try Again\n\n");
} // end switch 1
} // end while 1
return;} // end main
long int ncr( int n , int r ) {
long int a , b , c;
a = factorial(n) ;
b = factorial( n - r ) * factorial(r);
c = a / b ;
return(c); }
[ 本帖最后由 onlylonly 于 28-11-2005 08:02 PM 编辑 ] |
|