求100-500的质数
include
int main()
{
int i,j,n,f=1;
for(i=100;i<=500;i++){
f=1;
for(j=2;j<i/2;j++){
if(i%j==0){
f=0;
}
}
if(f==1){
printf("%d是质数\n",i);
}else{
printf("%d不是质数\n",i);
}
return(0);
}
C语言出租车计费
出租车计费问题。起步价10元 (三公里内),3~ 10公里之间的每公里2.1元,超出10公里部分每公里3元。输入行车里程,得出总费用。
include
int main(){
int a = 0;
float b = 0.0;
while(a <= 0){
printf("Please input a:\n");
scanf("%d",&a);
if(a>0 && a <= 3){
b = 10.0;
}else if(a>3 && a <= 10){
b = 10.0 + (a - 3) 2.1;
}else if(a>10){
b = 10.0 + 2.17+ (a - 10) * 3.0;
printf("输入错误,请重新输入\n");
printf("费用为 %f\n",b);
return 0;
C语言基本运算
include
int a = 100;
printf("%d\n",a++);//先用后加;100
printf("%d\n",a); //先加后用;101
printf("%d\n",++a);//先加后用;102
printf("%d\n",-a++);//先用后加;-102
printf("%d\n",a); //先加后用;103
printf("%d\n",a=5);//即时赋值;5
printf("%d\n",a=(6,6+a,8-a));//及时赋值;8-5=3
水仙花程序
//代码效果参考:http://www.zidongmutanji.com/zsjx/35879.html
void main()
int i,j,k;
for(i=0;i<=9;i++)
{
for(j=0;j<=9;j++)
{
for(k=0;k<=9;k++)
{
if(iii + jjj + kkk == i100+j10+k)
{
printf("%d %d %d \n",i,j,k);
}
}
指针基础
include
int *p = &a;
printf("%d \n",&a);
printf("%d",*p);
递归调用(迭代)求a的阶乘
int fib(int b)
int m=1;
if(b>1)
m=fib(b-1);
return b*m;
int a = 6;
printf("%d \n",fib(a));
冒泡排序法求10个数字的排序
int arr[10] = {9,8,7,6,5,4,3,2,1,0};
int temp;
for(int i=0;i<9;i++) for(int j=0;j<9-i;j++) if(arr[j] > arr[j+1])
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
for(int k = 0;k<=9;k++)
printf("%d,",arr[k]);
printf("\n");
8,7,6,5,4,3,2,1,0,9,
7,6,5,4,3,2,1,0,8,9,
6,5,4,3,2,1,0,7,8,9,
5,4,3,2,1,0,6,7,8,9,
4,3,2,1,0,5,6,7,8,9,
3,2,1,0,4,5,6,7,8,9,
2,1,0,3,4,5,6,7,8,9,
1,0,2,3,4,5,6,7,8,9,
0,1,2,3,4,5,6,7,8,9,
选择排序
int a[10]={18,12,10,84,30,16,78,9,21,38};
int i,j,k,temp;
for(i=0;i<10;i++)
printf("%d\t",a[i]);
printf("\n");
k=i;
for(j=i+1;j<10;j++)
if(a[k]>a[j]) k=j;
if(i!=k){
temp=a[i];
a[i]=a[k];
a[k]=temp;
//printf("%d和%d交换\n",a[i],a[k]);
for(int m=0;m<10;m++)
printf("%d\t",a[m]);
输出菱形图案
int line=3;
for(int i=1;i<=line;i++)
for(int j=line-i;j>0;j--)
printf("-");
for(int j=1;j<=i2-1;j++)
printf("");
for(int i=line+1;i<=line2-1;i++)
for(int j=1;j<i-line+1;j++)
for(int j=line4-i*2-1;j>=1;j--)
函数返回数组
int arrs(int b)
//在这里排序好
return b;
int a[] = {1,2,34,5};
int c;
c = arrs(a);
for(int i=0;i<=3;i++)
printf("%d \n",c[i]);
VB程序设计
字符串处理
Dim s As String
s = "abcdefg"
Print Right(s, 3) 'efg
Print Left(s, 3) 'abc
Print Mid(s, 3, 2) 'cd
If "a" < "b" Then
Print "真"
End If
If "caaaaa" < "d" Then
Private Sub Command1_Click()
Dim x As Double
Dim n As Integer
Dim n As Boolbean
Dim name As String 20
x = 13000000000
n = 0
Do While x <= 2600000000
x = x*1.008
n = n+1
Loop
If n >= 1 Then
Print "___"
Else
End If
Dim i As Integer
Dim j As Integer
For i = 0 To 5
Next
//代码效果参考:http://www.zidongmutanji.com/zsjx/3977.html
For i = 1 To 9
For j = 1 To i
S = i & "" & j & "=" & i j
Print Tab((j - 1) * 9); S;
Next j
Print ""
Next i
For i = 1 To 20 Step 2
Print i
Select Case d
Case 1
Print "___"
Case 2
Case 3
Case else
End Select
n = InputBox("请输入要判断的年份")
If n Mod 4 = 0 And n Mod 100 <>0 Or n Mod 400 = 0 Then
MsgBox "是闰年"
MsgBox "不是闰年"
End Sub
VB的选择排序
Dim d(20) As Single
n = Val(InputBox("请输入数据的总数里"))
For i = 1 To n
d(i) = Val(InputBox("请输入第" & i & "个数据"))
For t = 1 To n
Print d(t)
Next t
For i = 1 To n - 1
Min = d(i):
m = i
For j = i + 1 To n
If d(j) < Min Then
Min = d(j)
m = j
End If
If d(i) <> d(m) Then
Print "交换" & d(i) & "和" & d(m)
k = d(i)
d(i) = Min
d(m) = k
For t = 1 To n
Print d(t)
Next t
End If
生成20个10-100的随机数然后统计5的整数倍的和
Dim m As Integer
Dim sum As Integer
sum = 0
For m = 1 To 20
x = Int(10 + Rnd 91)
If x Mod 5 = 0 Then
Print x
sum = sum + x
Next m
Print "sum="; sum
Python语言备考
print(11//4) #整除得2
print(10*4) #10的4次方
for index in range(6):
print(index) #输出0到5
for index in range(6,10):
print(index) #输出6到9
print(4<=5<=6<=7) #输出True
print(4<=5<=6>=7) #输出False
print(len('R\0S\0T')) #输出5
d={"大海":"蓝色","天空":"灰色","大地":"黑色"}
print(d["大地"]) #黑色
print(d.get("天空","黄色")) #灰色
print(d.get("学校","黄色")) #黄色
a=[1,2,3]
print(id(a))
a.append(4)
print(a)