Any algorithm is done using for/while/do while/goto/recursion .
The logic ability of the algorithm is enhanced by using recursion to rewrite any loop.
Converts an integer to a string, a binary lookup, and a data separation.
Conversion of integer Strings:
#include <stdio.h> #include <stdlib.h>int tonum (char * str) { char * istr = str; int num = 0; while (*str != ') { if (*STR) < ' 0 ' | | (*STR) > ' 9 ') { return -1; } *str++; num++ } printf ("%d", num); int lastres = 0; for (int i = 0; i < num; i++) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBsp; lastres *= 10; int wei = istr[i] - 48; lastres += wei; printf ("\n wei = %d", wei) ; } return lastres;} Void tostr (INT&NBSP;NUM,&NBSP;CHAR&NBSP;*&NBSP;STR) { int wei = 0; for (int inum = num; inum; inum/=10) { wei++; } for (int i = wei - 1; num; num/=10, i--) { str[i] = num % 10 + 48; }}void main () {&nbsP;&NBSP;&NBSP;&NBSP;INT&NBSP;NUM&NBSP;=&NBSP;1234567;&NBSP;&NBSP;&NBSP;&NBSP;CHAR&NBSP;STR[10]&NBSP;=&NBSP;{0} ; tostr (NUM,&NBSP;STR); printf ("%s", str); getchar ();}
Recursion:
#define _CRT_SECURE_NO_WARNINGS//Close security check # include <stdio.h> #include <stdlib.h>double go (int n) {if (n = = 1 ) {return 1.0; } else if (n = = 2) {return 2.0; } else {return Go (n-1) +go (n-2); }}
Using While,do while, for, recursion, write out a binary lookup algorithm respectively.
Recursively determine if an array is decremented
The integer is converted to a string using the for, while, does while, Goto, recursively.
Recursive implementation 10-in-turn 8-binary
Recursively implements a string-to-integer (contains plus or minus), and the string is interchanged with double.
20160329--For/while/do while/goto/recursion