1.isPrime(y) function (judging whether a positive integer is a prime number)
int isPrime(int y)
{ int I = 2;
While (I & lt=y/2){if(y%i==0) returns 0; else i++; }
Returns1; } [If it is true (prime number), the return value is 1, otherwise it returns 0).
2. Output an integer n in reverse order from low order to high order.
(Enter n to omit)
And (n! =0){printf( "%d ",n % 10); n/= 10; }
3. Recursive method for outputting the nth term of Fibonacci sequence.
Intermediate fiber (intermediate fiber)
{if(n== 1) returns1;
If(n==2) returns1;
Otherwise, fib (n-1)+fib (n-2) is returned; ]
4. Output an integer n( 1) from high to low and store it in the array in reverse order, and then transpose it with the array.
int i=0j=0,t,a[80l; And (n! =0)
{ Ali]= n % 10; n/= 10; i++; ]
different
while(j & lt; i/2)
{ t = a[j+I- 1]; alj+I- 1]= aljl; aljl = t; ]
(2) Find the numbers first, and then output them in reverse order.
int a,i= 1,m,x,n,y; scanf("%d ",& ampa); And (m! =0){m=a/pow( 10,I); i++; } x = a;
for(I = I- 1; I>0; I-){ y = pow( 10i- 1); printf("%d\t ",n); x = x % y; }
5, bubble method to sort the number of n (from small to large)
-(array input ali] omitted)
for(j = 1; j & ltn; j++)for(I = 0; I< = n-j; i++)if(al[I]& gt; a[I+ 1]){ t = a[il; Ali]= a[I+ 1]; a[I+ 1]= t; ]
6. Sort by selection method (from small to large)
for(I = 0; I & ltn;; i++)
(k = I;
for(j = I+ 1; j & ltn; j++)if(alj]& lt; a[k])k = j;
If (me! =k)
(x = a[il; a[I]= a[k]; a[k]= x; }
7. Delete the specified character
void abc(char str[],char c){ int a,b;
for(a=b=0,str[a]! =' 10'; a++)if(str[a]! =c)
str[b++]= str[al;
str[b]= ' 10 '; }
8. Examples related to continuation and interruption
# include & ltstdio.h & gtvoid main(){ char s[]= " abcda " int k; char c; for(k = 1; c = s[k]; k++){
Switch (c)
{Case "a": putchar (%); Continue;
Case' b':++k; Break;
Default value: putchar (*);
Case C: Putchar (&; ); Continue; ]
putchar(#); }