1. output digital sequence 1,2,3,5,8,13,21 ..., the number of outputs is entered by the keyboard. Note Input using scanf input
A =1 b=0//a = 1 b=1//a= 2 b=1//////For example:////input 3 output for////1//2//3////input 4 output for//1//2//3//5int main (int argc,const char *argv[] ) { int a=1,b=0; int num; scanf ("%d", &num); for (int i=0; i<num; i++) { printf ("%d\n", a+b); int temp = A; A = A+b; b = temp; } return 0;}
2. Output digital sequence 1/1 2/1,3/2,5/3,8/5,13/8,21/13 ..., the number of outputs is entered by the keyboard. Note Input using scanf input
For example:////input 3 output is//a = 1 b= 1//2/1 a=2 b =1//3/2 a=3 b =2//5/3 a=5 b =3////input 4 output to//2/1//3/2//5/3//8/5int main (int argc, const char * argv[]) { int a=1; int b=1; int num; scanf ("%d", &num); for (int i=0; i<num; i++) { printf ("%d/%d\n", A+b, a); int temp = A; A= a+b; b = temp; } return 0;}
3. Process Control (for factorial and) input n (int type), print 1! +2! +3! +4! +5! + ... The value of the +n!
Input: 2//output://3////input: 3////output://9//6! = 6*5! = 6*5*4!;/ /SN = 1!//SN = 1! + 2*snint Main (int argc,const char *argv[]) { int n; int sum = 0; int temp=1; scanf ("%d", &n); for (int i=1; i<=n; i++) { temp *=i; sum + = temp; } printf ("sum =%d\n", sum); return 0;}
C language-part of the Loop excerpt 2