C程序设计的常用算法(国外英文资料).docVIP

  • 3
  • 0
  • 约1.45万字
  • 约 35页
  • 2017-07-05 发布于河南
  • 举报

C程序设计的常用算法(国外英文资料).doc

C程序设计的常用算法(国外英文资料)

C程序设计的常用算法 C programming commonly used algorithms Source: Electronic Engineer, note, madman, sea time: 2006-03-23 Publisher: Meitai Algorithm (Algorithm): basic ideas, methods, and procedures for computer problem solving. Description: is the algorithm to solve a problem or methods and steps taken to complete a task description, including what data (input output data, what what results, by what) structure, what statement and how to arrange these statements, etc.. Natural language, structured flowcharts, and pseudo code are often used to describe algorithms. I. simple algorithms for counting, summing, and calculating factorial Such problems need to use the cycle, we should pay attention to determine the initial value of the loop variable, the final value or termination conditions, but also pay attention to the enumeration, and the variables of the initial value of variables. Example: use random function to generate 100 [0, 99] range of random integers, statistics on the number of digits are 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, the number of numbers and print out. The array is used to handle the problem, and the array a[100] is used to store exactly 100 random integers, and the array x[10] to store the digits on the bit is 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, respectively. That is, the number of bits is 1, stored in x[1], and the number of bits is 2, stored in x[2],...... The number of bits is 0, stored in x[10]. Void, main () {int, a[101], x[11], I, p; For (i=0; i=11; i++) X[i]=0; For (i=1; i=100; i++) {a[i]=rand ()% 100; Printf (%4d, a[i]); If (i%10==0) printf (\n); } For (i=1; i=100; i++) {p=a[i]%10; If (p==0) p=10; X[p]=x[p]+1; } For (i=1; i=10; i++) {p=i; If (i==10) p=0; Printf (%d, %d\n, P, x[i]); } Printf (\n); } Two, for the two integer greatest common divisor and the least common multiple Analysis: the common denominator for the algorithm: (LCM = two integer product / GCD) (1) the m n, known for making mn; (2) m is divided by N, and the remainder is r; (3) if r=0, then n is

文档评论(0)

1亿VIP精品文档

相关文档