C 学习 2012-08-05

 1 #include <stdio.h>

 2 

 3 int main()

 4 {

 5     //实现幂函数 

 6     double power(double x, double y);

 7     

 8     printf("%f\n", power(2.0, 3.0));

 9     

10     //开跟号

11     double ssqrt(double x);

12     printf("%f\n", ssqrt(64.0));

13     

14     

15     //统计输入的数字、空白符(空格、制表符、回车符)以及所有其他字符出现的次数 

16     // F6 或者 Ctrl+Z  

17     

18     char c;

19     int numCount, blankCount,otherCount;

20     

21     numCount = blankCount = otherCount = 0;

22     

23     while((c = getchar()) != EOF)

24     {

25         if(c >= '0' && c <= '9')

26         {

27             numCount++;

28         }

29         else if(c == '\t' || c == ' ' || c == '\n')

30         {

31             blankCount++;

32         }

33         else

34         {

35             otherCount++;

36         }

37     

38     }

39     

40     printf("数字有%d个,空白符有%d个,其他字符有%d个", numCount, blankCount, otherCount);

41     

42 }

43 

44 

45 double ssqrt(double x)

46 {

47     int i;

48     double temp, result;

49     

50     for(i = 0; i < x ; i++)

51     {

52         temp = i * i;

53         if(temp == x)

54         {

55             result = i;

56             break;

57         }

58     }

59     

60     return result;

61 }

62 

63 double power(double x, double y)

64 {

65     int i;

66     double result;

67     

68     result = 1;

69     

70     for(i = 0; i < y / 2.0; i++)

71     {

72         result *= x;

73     }

74     

75     return result;

76     

77 }

你可能感兴趣的:(2012)