C学習2012-08-05

8797 ワード

 1 #include <stdio.h>

 2 

 3 int main()

 4 {

 5     //      

 6     double power(double x, double y);

 7     

 8     printf("%f
", power(2.0, 3.0)); 9 10 // 11 double ssqrt(double x); 12 printf("%f
", 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 == '
') 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 }