1. Calculate the factorial of any number (take 8 for example).
1#include <stdio.h>2 #defineNUM 8//3 4 /*function factorial (): The incoming parameter is the number of the factorial to be computed, and the method applied is calculated according to the calculation rule of factorial*/5 intFactorial (intnum);6 /*function Factorial1 (): The function is to apply recursive thought to calculate factorial*/7 intFactorial1 (intnum);8 Main ()9 {Tenprintf"%d\n", factorial (NUM)); Oneprintf"%d\n", Factorial1 (NUM)); A } - intFactorial (intnum) - { the intI,result; -I=1; -result=1; - + while(i<=num) - { +result=result*i; Ai++; at } - returnresult; - } - - intFactorial1 (intnum) - { in if(num==0|| num==1) - return 1; to Else + returnNum*factorial1 (num-1); - the}
2. Enter a line of characters, respectively, the number of English letters and numbers.
1#include <stdio.h>2 3 Main ()4 {5 Charch;6 intchar_num=0, int_num=0;7printf"Please enter the word representable \ n");8 while((Ch=getchar ())! ='\ n')9 {Ten if(ch>='a'&&ch<='Z'|| ch>='A'&&ch<='Z') Onechar_num++; A Else if(ch>='0'&&ch<='9') -int_num++; - } theprintf"Number of letters =%4d\n number =%4d\n", char_num,int_num); -}
C Language Programming topic (i)