c语言英文资料,C语言基本知识(国外英文资料).doc

C语言基本知识(国外英文资料)

C语言基本知识(国外英文资料)

If - else structure:

To write a calculator program, ask to enter two values from the keyboard, and then enter a four operator, automatically complete the output

Application of switch structure:

Enter A percentage score from the keyboard and ask for the output grade 'A' 'B' C 'D' E '. More than 90 is' A ', 80-89 is' B ', 70-79 is' C ', 60-69 is' D ', and 60 is' E '.

# include < stdio, h >

Void main ()

{float score;

Char grade;

Printf (" please enter student achievement: \ n ");

Scanf (" % f ", & score);

Switch ((int) (score / 10))

{case 10:

Case 9: grade = 'A'; Break;

Case 8: grade = 'B'; Break;

Case 7: grade = 'C'; Break; `

Case 6: grade = 'D'; Break;

Case 2: case 2: case 1: case 1:

Case 0: grade = 'E';

}

Printf (" the grade is % 5.1 f, the corresponding grade is % c. \ n ", score, grade);

}

The do-while loop:

The approximate value of PI is obtained by using the following formula, and the calculation accuracy is 0.0001

PI / 4 is approximately 1-1/3 + 1/5-1/7 + 1/9 -...

# include < stdio, h >

H # include < math.h >

Void main ()

{int s;

Float n, t, PI;

T = 1; PI = 0; N = 1.0; S = 1;

The do

{

PI = PI + t;

N + = 2;

S = -s;

T = s/n.

}

So while (1 / n) > 1e - 4);

Printf (" PI = % 10.6 f ", 4 * PI);

}

4 for loop applications:

(1) the sum of the primes. 20 integers from any keyboard, and all the prime Numbers are cumulative.

# include < stdio, h >

H # include < math.h >

Prime (int x [], int n)

{int I, j, k, s = 0;

For (I = 0; I < n; I + +)

{k = SQRT (x [I]);

For (j = 2; j < = k; + +)

If (x [I] % j = 0) break;

If (j > k) s + = x.

}

Return s;

}

The main ()

{int a [20], * p, s = 0, I;

P = a;

For (I = 0; I < 20; I + +)

Scanf (" % d ", p + +);

P = a;

S = prime (p, 20);

Printf (" % d ", s);

}

(2) the 3-digit problem without repeating Numbers. Use 1.2.3.4 to form a three-digit number without repeating Numbers, and output all of these three data.

# include < stdio, h >

Void main ()

{

Int I, j, k;

For (I = 1; I < = 2; I + +)

{

For (j = I + 1; j < = 3; j + +)

{

(k = j

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值