A few questions, exercise your mind

Source: Internet
Author: User

Not written for a long timeCodeI forgot, so I found some useful questions on the Internet a few days ago and wrote them for fun.

The following code is implemented in C.

1 9-9 multiplication table

# Include <stdio. h> Void  Main (){  Int  I;  Int  J;  For (I = 1 ; I <= 9 ; I ++ ){  For (J = 1 ; J <= I; j ++ ) {Printf (  "  % D x % d = % d  " , J, I, I * J); printf (  "   "  );} Printf (  "  \ N  "  );}} 

2 Bubble Sorting

# Include <stdio. h>Void  Main (){  Int  I, J;  Int  Temp;  Int A [ 10 ] = { 1 , 5 , 7 , 8 , 2 , 0 , 3 ,6 , 4 , 9  };  For (I = 0 ; I < 10 ; I ++ ){  For (J = 0 ; J <I; j ++ ){  If (A [J]> A [J + 1  ]) {Temp =A [J]; A [J] = A [J + 1  ]; A [J + 1 ] = Temp ;}}}  For (I = 0 ; I < 10 ; I ++ ) {Printf (  "  % D \ n  "  , A [I]) ;}} 

3. Search for prime numbers -.

# Include <stdio. h>VoidMain (){IntI;For(I =100; I <200; I ++){If(I %2=1) {Printf ("% D \ n", I );}}}

4. How many daffodils are there -?

# Include <stdio. h> Void Main (){  Int  A;  Int  I, J, K;  For (A = 100 ; A <= 999 ; A ++ ) {I = ( Int ) (/ 100  ); J = ( Int ) (A % 100 )/ 10 ); K = A % 10  ;  If (A = getcube (I) + getcube (j) + Getcube (k) {printf (  "  % D \ n  "  , A); printf (  "  % D, % d, % d \ n  "  , I, j, k );}}}  Int Getcube ( Int A ){  Return A * * A ;} 

5. 5!

 # include 
   
    void  
    main () { 
    int  
   ; A  = GCB (
    5  
    ); printf ( 
    " 
    % d \ n  
   "  
   ,a) ;} 
    int  GCB (
    int  
   ) { 
    If  (! = 
    1  
   ) { 
    return  A * GCB (a-
    1  
   ) ;} 
    else  
    return  
    ;}  
  

6. Enter a two-dimensional array to obtain the sum of diagonal elements.

# Include <stdio. h> Void  Main (){  Int A [ 3 ] [ 3  ];  Int  I, J;  Int Temp = 0  ;  For (I = 0 ; I <3 ; I ++ ){  For (J = 0 ; J < 3 ; J ++ ) {Scanf (  "  % D  " ,& A [I] [J]) ;}}  For (I = 0 ; I < 3 ; I ++ ){ For (J = 0 ; J < 3 ; J ++ ){  If (I = j | ABS (I-j) = 2  ) {Temp = Temp + A [I] [J] ;}} printf (  "  % D \ n  "  , Temp );} 

 

These are all questions I made when I went to school, but now it seems quite interesting. I really don't know what to do on the Internet.ProgramAh.
There are 50 questions in this link. You can refer to the question: http://bbs.csdn.net/topics/110067294.

Note: I am not a programmer. I just write code out of my personal hobbies or bored online. Please do not read or comment if you think you code yourself, so that you do not have to delete the comment, seriously, you lose.

If you want to discuss database technology, you can add our group: 120244471.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.