注意:要用到counter,number,largest三个变量
编写一个程序,读取一个非负整数,计算并打印出它的阶乘。
n=n*(n-1).......*1
#include "stdio.h" main() { int counter[10];int number,largest; printf("please input 10 number:"); for(number=0;number<=9;number++) { scanf ("%d",&counter[number]);
} largest=0; for (number=1;number<=9;number++) { if ( counter[number]>counter[largest] )
largest= number; } printf("the result is %d", counter[largest]); getch(); } c语言群9771099
#include <stdio.h> #include <stdlib.h>
void main() { int *counter,number,largest,i; printf("Please the piece of input the comparison data:"); scanf("%d",&i); counter=(int*)malloc(i*sizeof(int)); printf("\nPlease input the number:"); for(number=0;number<i;number++) { scanf("%d",counter+number); } largest=*(counter); for(number=1;number<i;number++) { if(*(counter+number)>largest) { largest=*(counter+number); } } printf("Biggest value is: %d\n",largest); free(counter); } 本程序用指针实现不局限比较的数的多少,我用指针写只是想多练练没有别的意思。
[此贴子已经被作者于2005-10-9 16:49:49编辑过]