5. C Language Learning ------------ C language applets

Source: Internet
Author: User

C Language Program
1. Multiplication table (using arrays)
# Include <stdio. h>
Int main (void ){
Int a [9];
Int c [9];
Int x;
Int y;
For (x = 1; x <= 9; x ++ ){
A [x] = x;
}
For (y = 1; y <= 9; y ++ ){
C [y] = y;
}
For (x = 1; x <= 9; x ++ ){
For (y = 1; y <= x; y ++ ){
Printf ("% d * % d = % d", a [x], c [y], a [x] * c [y]);
}
Printf ("\ n ");
}
Return 0;
}

2. Implementation of daffodils
# Include <stdio. h>
Int main (void ){
Int a, B, c, sum;
For (a = 1; a <= 9; a ++ ){
For (B = 0; B <= 9; B ++ ){
For (c = 0; c <= 9; c ++ ){
Sum = a * 100 + B * 10 + c;
If (sum = a * a + B * B + c * c ){
Printf ("% d \ n", sum );
}
}
}
}
Return 0;
}
3. Enter the password of a banking system to limit the number of inputs (do... while Statement)
# Include <stdio. h>
Int main (void ){
Int password;
Int count = 0;
Printf ("your password can only be entered three times, more than three times will be locked! \ N ");
Do {
If (count <3 ){
Printf ("enter your password: \ n ");
Scanf ("% ld", & password );
Printf ("Incorrect password, think about \ n ");
}
Else if (3 = count ){
Printf ("wrong password, card to be locked! ");
}
Count ++;
}
While (123456! = Password );
Printf ("go to the banking system !! ");
}

4. A number plus 100 is a worker number plus 168 or a worker number ..
# Include <stdio. h>
Int main (void ){

Long int I, x, y;
For (I = 1; I <100000; I ++ ){
X = sqrt (I + 100 );
Y = sqrt (I + 268 );

If (x * x = I + 100 & y * y = I + 268)
Printf ("\ n % ld \ n", I );
}
}


5. Enter two numbers to calculate the average value
# Include <stdio. h>
Int main (void ){
Int count, sun, anInteger;
Printf ("Enter the inteegers and terminate with negtive number \ n ");
Count = 0;
Sun = 0;
Printf ("Enter number % d:", count + 1 );
Scanf ("% d", & anInteger );
While (anInteger> = 0 ){
Sun + = anInteger;
Count ++;
Printf ("Enter number % d:", count + 1 );
Scanf ("% d", & anInteger );
} If (count! = 0 ){
Printf ("The average is % f \ n", sun/(double) count );
} Else {
Printf ("You enteed no numbers \ n ");
}
Return 0;
}


From 10-3G-He Jinchao

Related Article

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.