提示2-3 编写程序时,要特别留意“当前行”的跳转和变量的改变。函数
例题2-1 aabbspa
输出全部形如aabb的四位彻底平方数(即前两位数字相等,后两位数字也相等)。操作系统
方法1:code
1 #include <stdio.h> 2 #include <math.h> 3 4 int main() 5 { 6 int a, b, n; 7 double m; 8 9 for (a = 1; a <= 9; a++) 10 for (b = 0; b <= 9; b++) 11 { 12 n = a * 1100 + b * 11; 13 m = sqrt(n); 14 if (floor(m + 0.5) == m) 15 printf("%d\n", n); 16 } 17 18 return 0; 19 }
方法2:blog
1 #include <stdio.h> 2 3 int main() 4 { 5 int x, n, high, low; 6 7 for (x = 1; ; x++) 8 { 9 n = x * x; 10 if (n < 1000) continue; 11 if (n > 9999) break; 12 high = n / 100; 13 low = n % 100; 14 if (high/10 == high%10 && low/10 == low%10) 15 printf("%d\n", n); 16 } 17 18 return 0; 19 }
提示2-13: 能够使用time.h和clock()函数得到程序运行时间。常数CLOCKS_PER_SEC和操做系统相关,请不要直接使用clock()的返回值,而应老是除以CLOCKS_PER_SEC。 io
scanf函数也有返回值,它返回的是成功输入的变量的个数;当输入结束时,scanf没法再次读取则返回0。class
提示2-15:在Windows下,输入完毕后先按Enter键,再按CTRL+Z键,最后再按Enter键,便可结束输入。在Linux下,输入完毕后按CTRL+D键便可结束输入。变量
提示2-16:变量在未赋值以前的值是不肯定的。特别地,它不必定等于0。程序