第二周实验报告

来源:互联网 发布:杀马特网络四大家族 编辑:程序博客网 时间:2024/05/16 09:24
  • #include <iostream> 
  •  
  • using namespace std; 
  •  
  • void d2d (int n); 
  •  
  • int main (void
  •     int a; 
  •  
  •     cin >> a; 
  •  
  •     d2d (a); 
  •  
  •     cout << endl; 
  •  
  •     return 0; 
  •  
  • void d2d (int n) 
  •     if (n == 0) 
  •     { 
  • cout << 0;
  •     } 
  •     else if (n == 1) 
  •     { 
  •         cout << 1; 
  •     } 
  •     else  
  •     { 
  •         d2d (n / 2); 
  •  
  •         cout << n % 2; 
  •     } 
  • #include <iostream> 
  •  
  • using namespace std; 
  •  
  • long fac (int n); 
  •  
  • int main (void
  •     int m, n;  
  •  
  • cin >> m >> n;
  •  
  •     cout << fac (m) / fac (n) / fac (m - n) << endl; 
  •  
  •     return 0; 
  •  
  • long fac (int n) 
  •     int s; 
  •  
  •     if (n == 1) 
  •     { 
  •         return 1; 
  •     } 
  •     else  
  •     { 
  •         s = n * fac (n - 1); 
  •     } 
  •     return s; 
  • #include <iostream> 
  •  
  • #include <string.h> 
  •  
  • using namespace std; 
  •  
  • int main (void
  •     char input [50]; 
  •  
  •     gets(input); 
  •  
  •     int num = 1;  
  •     for (int i = 1; i < 50; ++i) 
  •     { 
  •         if ((input [i - 1] !=' ') && (input [i] == ' ')) 
  •         { 
  •             ++num; 
  •         } 
  •     } 
  •     cout << "There are " << num <<" words in the line." << endl; 
  •  
  •     return 0; 
  • #include <iostream> 
  •  
  • #include <string.h> 
  •  
  • using namespace std; 
  •  
  • int main (void
  •     char input [50]; 
  •      
  •     char cpyinput [50]; 
  •      
  •     gets (input); 
  •      
  •     int c = 0;   
  •      
  •     for (int i = 0, j = 0; i < 50; ++i) 
  •     { 
  •         if (input [i] !=' ' && input [i] != '\0'
  •         { 
  •             c = 1; 
  •         } 
  •          
  •         if (c == 1) 
  •         { 
  •             cpyinput [j] = input [i]; 
  •              
  •             if (input [i] == '.' || input [i] == '!' || input [i] ==',' || input [i] == ';' || input [i] =='?'
  •             { 
  •                 cpyinput [j + 1] = ' '
  •                  
  •                 ++j; 
  •  
  •                 if (input [i + 1] ==' '
  •                 { 
  •                     ++i; 
  •                 } 
  •             } 
  •              
  •             ++j; 
  •         } 
  •          
  •         if (input [i] ==' '
  •         { 
  •             c = 0; 
  •         } 
  •     } 
  •      
  •     cout << cpyinput << endl; 
  •  
  •     return 0; 

  •  

     
     



















  • 原创粉丝点击