C 粂ē 量竡 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 A B C
芠├: ﹚ㄧ计 - ﹚ㄇㄧ计ㄓㄏノ (筿福⊿矗ㄑ)
Ч俱ㄒ1硈尿ㄢΩ hello
<糶猭>
#include<stdio.h>
void main() //祘Α场
{
printf("+-------+");
printf("| hello |");
printf("+-------+);
printf("+-------+");
printf("| hello |");
printf("+-------+);
}
<ㄧ计糶猭>
#include<stdio.h>
void print_hello() //﹚ㄧ计 print_hello 场
{
printf("+-------+");
printf("| hello |");
printf("+-------+");
}
void main() //祘Α场
{
print_hello(); //㊣ print_hello ㄧ计
print_hello(); //㊣ print_hello ㄧ计
}
絤策1硈尿Ω help :
+------+
| help |
+------+
+------+
| help |
+------+
+------+
| help |
+------+
芠├: ﹚ㄧ计 - ﹚ㄇ计厩ㄧ计ㄓㄏノ (筿福⊿矗ㄑ)
Ч俱ㄒ2璸衡 20 + 21 + 22 + 23 + ...... + 100挡狦
<糶猭>
#include<stdio.h>
void main()
{
int i,sum;
sum = 0;
for(i=20;i<=100;i=i+1)
{
sum = sum + i;
}
printf("%d \n",sum);
}
<ㄧ计糶猭>
#include<stdio.h>
int summary(int low,int high) //﹚ㄧ计 summary 场
{
int i,sum;
sum = 0;
for(i=low;i<=high;i=i+1)
{
sum = sum + i;
}
return sum;
}
void main() //祘Α场
{
int a;
a = summary(20,100); //㊣ summary ㄧ计
printf("%d \n",a);
}
絤策2璸衡 21 + 22 + 23 + ...... + 30 + 41 + 42 + 43 + ...... + 50 +61 + 62 +63 + ...... + 70挡狦
芠├: ﹚ㄧ计 - 冈阶"把计"㎝"肚"
祘Α ⌒⌒⌒≈ ﹚ㄧ计
把计
祘Α ≌⌒⌒⌒ ﹚ㄧ计
肚
猵⊿Τ肚把计⊿Τ肚肚
Ч俱ㄒ3硈尿ㄢΩ︽ *
#include<stdio.h>
void print_one_row_star() //﹚ㄧ计 场
{
int i;
for(i=0;i<=70;i=i+1)
{
printf("*");
}
printf("\n");
}
void main() //祘Α场
{
print_one_row_star();
print_one_row_star();
}
絤策3︽ *い丁︽ Hello, Nice to meet you. ︽ *
猵Τ肚把计⊿Τ肚肚
Ч俱ㄒ4硈尿ㄢΩ︽ *祘Α穦禗﹚ㄧ计︽い璶碭 *
#include<stdio.h>
void print_one_row_star(int n) //﹚ㄧ计 场
{
int i; //祘Α i
㎝ ﹚ㄧ计 iㄢ礚闽
for(i=0;i<=n;i=i+1)
{
printf("*");
}
printf("\n");
}
void main() //祘Α场
{
int i=30; //祘Α
i ㎝ ﹚ㄧ计 iㄢ礚闽
print_one_row_star(20);
print_one_row_star(i);
}
絤策4糶ㄧ计ㄓ瓜祘Α穦禗﹚ㄧ计璶Τ碭 *
****
***
**
*
猵Τ肚把计Τ肚肚
Ч俱ㄒ5糶ㄧ计ㄓ璸衡 a + (a+1) + (a+2) + ...... + b祘Α穦禗﹚ㄧ计 a ㎝ b 琌ぶτ﹚ㄧ计穦盢衡ㄓ禗祘Α
#include<stdio.h>
int summary(int a,int b) //﹚ㄧ计 summary 场
{
int i,sum;
sum = 0;
for(i=a;i<=b;i=i+1)
{
sum = sum + i;
}
return sum;
}
void main() //祘Α场
{
int a;
a = summary(20,100); //㊣ summary ㄧ计
printf("%d \n",a);
}
絤策5糶ㄧ计ㄓ璸衡àà弊娩祘Α穦禗﹚ㄧ计 ab (a㎝b àààㄢ娩)τ﹚ㄧ计穦盢衡ㄓ弊娩禗祘Α
﹚ㄧ计砏玥
1. 祘Αいㄏノ﹚ㄧ计璶︽(﹚ㄧ计璶耚祘Α)
2. 祘Αいㄏノ﹚ㄧ计籔い﹚ㄧ计把计(跑计)计璶单把计篈璶把计嘿ぃ
3. ﹚ㄧ计璝礚 肚玥恶 void , 玥, 恶 肚 篈 (祘Α琌)
4. ﹚ㄧ计璝Τ 肚玥祘Αいㄏノ﹚ㄧ计璶ノ篈跑计ㄓ纗
5. 祘Αいㄏノ﹚ㄧ计璝嘿籔秈ㄓㄧ计玥璶跌把计τ﹚
Ч俱ㄒ6 ㄏノ﹚ㄧ计璝嘿籔秈ㄓㄧ计
<把计计ぃ>
#include<stdio.h>
#include<math.h>
double pow(double i)
{
return i*i;
}
void main()
{
printf(" %lf \n",pow(4.0,3.0));
printf(" %lf \n",pow(4.0));
}
<把计计>
#include<stdio.h>
#include<math.h>
double pow(double i,double j)
{
return i*j;
}
void main()
{
printf(" %lf \n",pow(4.0,3.0));
}
絤策6刚糶ノàㄓ璸衡 sin() ㄧ计 ( 筿福 sin ㄧ计琌ノ┓ㄓ璸衡)
糶籔ぃ糶﹚ㄧ计ゑ耕
ゑ耕 | Τ祘Α | Τ祘Α ㎝ ㄧ计 |
纔 | ぃ斗σ納把计肚计肚患 | だ |
| ぃ綷弄 | σ納把计肚肚患 |
ㄒ | void main() { int sum,a[3]={1,2,3}; sum = a[0]+a[1]+a[2]; cout << sum ; } |
int cal1(int a,int b,int c) { return a+b+c; } void main() { int sum,a[3]={1,2,3}; sum = cal1(a[0],a[1],a[2]); cout << sum ; } |