C Language Programming topic (i)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.