第一個(gè):
公司主營(yíng)業(yè)務(wù):做網(wǎng)站、網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出靈臺(tái)免費(fèi)做網(wǎng)站回饋大家。
#include stdio.h
main()
{
float s=0.0,t=0.0;
printf("gongzi:\n");
scanf("%f",s);
if (s0)
printf("0");
else if (s1000)
{t=0.0 ;
printf("gongzi:%5.2f,shui:%5.2f,shifagongzi:%5.2f",s,t,s-t); }
else if (s=1000 s2000)
{t=s*0.05;
printf("gongzi:%5.2f,shui:%5.2f,shifagongzi:%5.2f",s,t,s-t); }
else if (s=2000 s3000)
{t=s*0.08;
printf("gongzi:%5.2f,shui:%5.2f,shifagongzi:%5.2f",s,t,s-t); }
else if (s=3000 s5000)
{t=s*0.10;
printf("gongzi:%5.2f,shui:%5.2f,shifagongzi:%5.2f",s,t,s-t); }
else if (s=5000)
{t=s*0.15;
printf("gongzi:%5.2f,shui:%5.2f,shifagongzi:%5.2f",s,t,s-t); }
getch();
}
第2個(gè):
main()
{
int day,x1,x2;
day=9;
x2=1;
while(day0)
{x1=(x2+1)*2;/*第一天的桃子數(shù)是第2天桃子數(shù)加1后的2倍*/
x2=x1;
day--;
}
printf("the total is %d\n",x1);
第3個(gè):
#include stdio.h
#define N 3
#define M 3
main()
{
int a[N][M],sum[N]={0};
double avg[N];
int i,j;
for(i=0;iN;i++)
{
printf("Input the %dth student's scores:",i+1);
for(j=0;jM;j++)
{
scanf("%d",a[i][j]);
sum[i]+=a[i][j];
}
avg[i]=(double)sum[i]/M;
}
printf("The sums are:");
for(i=0;iN;i++)
printf("%4d",sum[i]);
printf("\nThe averages are:");
for(i=0;iN;i++)
printf("%6.2lf",avg[i]);
printf("\n");
}
第4個(gè):
#define N 4
int array[N][N];
void convert(int array[3][3]) /*函數(shù)類型可定義為void,也可用默認(rèn)的int*/
{int i,j,t; /*因?yàn)楹瘮?shù)形實(shí)參是數(shù)組,按地址傳遞*/
/*兩個(gè)數(shù)組所用空間相同,函數(shù)無需返回值*/
for(i=0;iN;i++)
for(j=i+1;jN;j++) /* j=i+1防止兩元素對(duì)調(diào)后再次恢復(fù)原位 */
{t=array[i][j];
array[i][j]=array[j][i];
array[j][i]=t;
}
}
main()
{
int i,j;
void convert(int [][]); /*注意此處的 [ ][ ] 形式,表明是二維數(shù)組*/
printf("Input array:\n"); /* 因?yàn)楹瘮?shù)原型處僅檢查形參個(gè)數(shù)、類型名、
for(i=0;iN;i++) /* 順序,而不檢查形參名。所以只寫成[ ][ ] 形式
for(j=0;jN;j++) /* 即可。僅對(duì)void時(shí)如此,對(duì)int似乎不成立?*/
scanf("%d",array[i][j]);
printf("\noriginal array:\n");
for(i=0;iN;i++)
{for(j=0;jN;j++)
printf("%5d",array[i][j]);
printf("\n");
}
convert(array);
printf("convert array:\n");
for(i=0;iN;i++)
{for(j=0;jN;j++)
printf("%5d",array[i][j]);
printf("\n");
}
}
第5個(gè):
#define nmax 50
main()
{
int i,k,m,n,num[nmax],*p;
printf("please input the total of numbers:");
scanf("%d",n);
p=num;
for(i=0;in;i++)
*(p+i)=i+1;
i=0;
k=0;
m=0;
while(mn-1)
{
if(*(p+i)!=0) k++;
if(k==3)
{ *(p+i)=0;
k=0;
m++;
}
i++;
if(i==n) i=0;
}
while(*p==0) p++;
printf("%d is left\n",*p);
}
你看懂了嗎?看懂就送分吧
如果看不懂你就是瞎問
再送點(diǎn)詳解給你
#include stdio.h
#define N 50 // 排隊(duì)人數(shù)(可任意更改)
#define CAL 3 //凡報(bào)3的人出列(可任意更改)
//下面是排隊(duì)編號(hào)函數(shù):從h 開始的n個(gè)人依次編號(hào)1到n
void stdline(int *h,int n)
{
int i;
for(i=1;in+1;i++) *(h+i-1)=i;
}
/*下面函數(shù)表示從指針h處開始的人數(shù)為boy個(gè)人排隊(duì),從1報(bào)數(shù),每報(bào)到call的人出列*/
void outline(int *h,int boy,int call)
{
int *p, chu, callnum;
/*說明:
p 工作指針,表示從頭依次指向每個(gè)元素,點(diǎn)名
chu 計(jì)數(shù)器,記錄出列的人數(shù)
callnum 計(jì)數(shù)器,記錄點(diǎn)名次序
*/
chu=0;
callnum=0;//各計(jì)數(shù)器清零
p=h; //開始時(shí),工作指針指向數(shù)組首
printf("出列順序是:\n");
while(chuboy)
{
if(*p!=0) callnum++; //每次加報(bào)數(shù)
if(callnum==call) //如果某一個(gè)人報(bào)到出列數(shù)call...
{
printf("%5d",*p); //打印編號(hào),表示出列
chu++; //出列人數(shù)加1
if(chu==boy)//如果全部出列....
{
*h=*p; //把最后一個(gè)出列人的編號(hào)記入地址開始處
return; //結(jié)束
}
if(chu%10==0)printf("\n");//每輸出10個(gè)換行
callnum=0; //出列后,重新報(bào)數(shù)
*p=0; //出列后,將其編號(hào)賦零,以示區(qū)別
}
p++; //工作指針移向下一個(gè)人,即下一個(gè)數(shù)組元素
if(ph+boy-1)p=h;/*如果移到最后一個(gè)元素的后面,則讓指向地址開頭繼續(xù)報(bào)數(shù)*/
}
}
void main()
{
int a[N]; //用數(shù)組模擬隊(duì)列,每個(gè)元素代表一個(gè)人
stdline(a,N);//編號(hào)
outline(a,N,CAL);//計(jì)算并打印出列順序
printf("\n最后留下來的是 %d 號(hào)\n",*a);/*在函數(shù)中,已經(jīng)把最后一個(gè)人的編號(hào)寫入了數(shù)組首地址處,
這里輸出就可以了*/
}
第6個(gè):
#includestdio.h
struct date
{
int year;
int month;
int day;
}date;
void main()
{
int sum=0,leap;
printf("\n請(qǐng)輸入日期(年,月,日)\n");
scanf("%d,%d,%d",date.year,date.month,date.day);
switch(date.month)//先計(jì)算某月以前月份的總天數(shù)。
{
case 1:sum=0;break;
case 2:sum=31;break;
case 3:sum=59;break;
case 4:sum=90;break;
case 5:sum=120;break;
case 6:sum=151;break;
case 7:sum=181;break;
case 8:sum=212;break;
case 9:sum=243;break;
case 10:sum=273;break;
case 11:sum=304;break;
case 12:sum=334;break;
default:printf("data error");
break;
}
sum=sum+date.day;//再加上某天的天數(shù)。
if(date.year%400==0||(date.year%4==0date.year%100!=0))
leap=1;
else
leap=0;
if(leap==1date.month2)//如果是閏年且月份大于2,總天數(shù)應(yīng)該加一天。
sum++;
printf("這天是當(dāng)年的第 %d 天。\n",sum);
}
寫不下了。。。
你看我的理解對(duì)不。如果有問題,HI我。
/*表達(dá)的有點(diǎn)不清楚,如果x是20000,按10%算還是按20%算*/
#includestdio.h
int main(void)
{
double tax=0,money,m;
int c;
printf("請(qǐng)輸入全年應(yīng)納所得額數(shù)目:\n");
scanf("%lf",money);
m=money;
if(money/100008)
c=8;
else
c=(int)money/10000;
switch(c)//找到一個(gè)入口,順次相加各個(gè)級(jí)應(yīng)納稅額。
{
case 8:tax+=(money-80000)*0.35;money=80000;
case 7:
case 6:
case 5:
case 4:tax+=(money-40000)*0.30;money=40000;
case 3:
case 2:tax+=(money-20000)*0.20;money=20000;
case 1:tax+=(money-10000)*0.10;money=10000;
case 0:tax+=money*0.05;break;
default:printf("Data Error!\n");
}
printf("應(yīng)納稅額:%.2f\n",tax);
printf("最終所得:%.2f\n",m-tax);
return 0;
}
為了便于你驗(yàn)證程序執(zhí)行結(jié)果:下面的可以多次執(zhí)行,直到你輸入的money不大于0.
#includestdio.h
int main(void)
{
while(1)
{
double tax=0,money,m;
int c;
printf("請(qǐng)輸入全年應(yīng)納所得額數(shù)目:\n");
scanf("%lf",money);
if(money=0)
break;
m=money;
if(money/100008)
c=8;
else
c=(int)money/10000;
switch(c)//找到一個(gè)入口,順次相加各個(gè)級(jí)應(yīng)納稅額。
{
case 8:tax+=(money-80000)*0.35;money=80000;
case 7:
case 6:
case 5:
case 4:tax+=(money-40000)*0.30;money=40000;
case 3:
case 2:tax+=(money-20000)*0.20;money=20000;
case 1:tax+=(money-10000)*0.10;money=10000;
case 0:tax+=money*0.05;break;
default:printf("Data Error!\n");
}
printf("應(yīng)納稅額:%.2f\n",tax);
printf("最終所得:%.2f\n",m-tax);
}
return 0;
}
是調(diào)用函數(shù),接收返回值嗎?用
變量類型名 變量名=函數(shù)名(參數(shù)列表);
如:
int r;
int F(int n)
{
return n*100;
}
r=F(6);
實(shí)用計(jì)算器之程序設(shè)計(jì)
[摘 要]多用計(jì)算器的構(gòu)思及設(shè)計(jì)代碼
[關(guān)鍵詞]多用計(jì)算器;設(shè)計(jì)
數(shù)值計(jì)算可以說是日常最頻繁的工作了,WIN98提供了“計(jì)算器”軟件供用戶使用,該軟件可以處理一般的一步四則運(yùn)算,例如:3+2、5/3等等,但在日常中用戶經(jīng)常遇到多步四則運(yùn)算問題,例如:3+4*5-4/2,45*34/2+18*7等等,那么該個(gè)計(jì)算器就無法勝任了,作者制作了一個(gè)實(shí)用的計(jì)算器,該計(jì)算器新增不少功能:(程序界面如圖)
1.可以實(shí)現(xiàn)連續(xù)的四則運(yùn)算
2.可以實(shí)現(xiàn)輸入式子的顯示
3.可以方便計(jì)算個(gè)人所得稅
4.鼠標(biāo)、鍵盤均可輸入數(shù)據(jù)
5.操作界面友好
6.擊鍵可發(fā)聲
構(gòu)建該個(gè)計(jì)算器所需研究及解決的核心問題有如下幾個(gè):1、連乘求值?2、字符顯示 3、鍵盤輸入?4、擊鍵發(fā)聲?5、個(gè)人所得稅法規(guī),為了使大家對(duì)程序有更一步認(rèn)識(shí),現(xiàn)將代碼提供給讀者參考:
*定義數(shù)組及窗體變量
Dim number2(0 To 50) As Double
Dim number(0 To 50) As Double
Dim z As Integer
Dim k As Integer, r As Integer
Dim j As Integer
Dim str As String
*調(diào)用名為“playsound”的API函數(shù)
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME = H20000?
Private Const SND_ASYNC = H1?
Private Const SND_SYNC = H0
*判斷通用過程
Sub pianduan(p As String)
r = 0
Dim i As Integer, l As Integer, h As Integer
h = 0
i = 1
If InStr(Trim$(p), "*") 0 Then
k = k + 1
End If
If InStr(Trim$(p), "/") 0 Then
r = r + 1
End If
End Sub
*連乘通用過程(略)
*各按鈕事件過程
Private sub Command1_Click(Index As Integer)
PlaySound App.Path "\start.wav", 0, SND_SYNC
Text1.Text = Text1.Text + Command1(Index).Caption
Text2.Text = Text2.Text + Command1(Index).Caption
Text1.SetFocus
End Sub
rivate sub Command10_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
str = Text3.Text
End Sub
Private sub Command11_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
Text3.Text = str
End Sub
rivate sub Command2_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k = 1 Or r = 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "+"
z = z + 1
Text1.SetFocus
End Sub
rivate sub Command3_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k = 1 Or r = 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "-"
Text1.Text = Text1.Text "-"
z = z + 1
Text1.SetFocus
End Sub
Private sub Command4_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
Text2.Text = Text2.Text + "*"
Text1.Text = Text1.Text + "*"
Text1.SetFocus
End Sub
rivate sub Command5_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
Text2.Text = Text2 + "/"
Text1.Text = Text1 + "/"
Text1.SetFocus
End Sub
Private sub Command6_Click()
PlaySound App.Path "\sound.wav", 0, SND_SYNC
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k = 1 Or r = 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
z = z + 1
Dim dengyu As Double
Dim v As Integer
For v = 0 To 50
dengyu = dengyu + number2(v)
Next v
If dengyu 0 Then
Text3.ForeColor = HFF
Else
Text3.ForeColor = HFF0000
End If
Text3.Text = dengyu
Text1.SetFocus
If Len(Text3.Text) = 14 Then
calcresult.Show
End If
End Sub
rivate sub Command7_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
z = 0: k = 0: r = 0: j = 0
Dim i As Integer
For i = 0 To 50
number(i) = 0
number2(i) = 0
Next i
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub
rivate sub Command8_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
If Val(Text3.Text) = 0 Then
MsgBox "除數(shù)不能為0!"
Exit Sub
End If
Text3.Text = 1 / Val(Text3.Text)
End Sub
Private sub Command9_Click()
PlaySound App.Path "\start.wav", 0, SND_SYNC
Text3.ForeColor = HFF0000
Text3.Text = Val(Text3.Text) * Val(Text3.Text)
End Sub
rivate sub muninternet_Click()
Dim i
i = Shell("C:\Program Files\InternetExplorer\iexplore.exe", vbMaximizedFocus)
End Sub
rivate sub munmp3_Click()
Dim i
i = Shell("C:\Program Files\Windows Media Player\mplayer2", vbNormalNoFocus)
End Sub
Private sub munsm_Click()
Dialog.Show
End Sub
rivate sub muntax_Click()
tax.Show
End Sub
rivate sub munver_Click()
ver.Show
End Sub
rivate sub notepad_Click()
Dim i
i = Shell("c:\windows\notepad", vbNormalFocus)
End Sub
Private sub Text1_KeyPress(KeyAscii As Integer)
PlaySound App.Path "\start.wav", 0, SND_SYNC
Dim num As Integer
num = Val(KeyAscii)
If num 47 And num 58 Then
Text1.Text = Text1.Text + CStr(num - 48)
Text2.Text = Text2.Text + CStr(num - 48)
End If
If num = 46 Then
Text1.Text = Text1.Text + "."
Text2.Text = Text2.Text + "."
End If
If KeyAscii = 43 Then
Dim totle As Double
Dim n As Integer
Call pianduan(Text1.Text)
If k = 1 Or r = 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "+"
z = z + 1
End If
If KeyAscii = 45 Then
Call pianduan(Text1.Text)
If k = 1 Or r = 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
Text2.Text = Text2 + "-"
Text1.Text = Text1.Text "-"
z = z + 1
End If
If KeyAscii = 42 Then
Text2.Text = Text2.Text + "*"
Text1.Text = Text1.Text + "*"
End If
If KeyAscii = 47 Then
Text2.Text = Text2.Text + "/"
Text1.Text = Text1.Text + "/"
End If
If KeyAscii = vbKeyReturn Then
PlaySound App.Path "\sound.wav", 0, SND_SYNC
Call pianduan(Text1.Text)
If k = 1 Or r = 1 Then
Call liancheng(totle)
number2(z) = totle
If Mid$(Trim$(Text1.Text), 1, 1) = "-" Then
number2(z) = -totle
End If
k = 0: r = 0
Else
number2(z) = Val(Text1.Text)
End If
Text1.Text = ""
z = z + 1
Dim dengyu As Double
Dim v As Integer
For v = 0 To 50
dengyu = dengyu + number2(v)
Next v
If dengyu 0 Then
Text3.ForeColor = HFF
Else
Text3.ForeColor = HFF0000
End If
Text3.Text = dengyu
End If
If KeyAscii = vbKeyEscape Then
z = 0: k = 0: r = 0: j = 0
Dim i As Integer
For i = 0 To 50
number(i) = 0
number2(i) = 0
Next i
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End If
If Len(Text3.Text) = 14 Then
calcresult.Show
End If
End Sub
rivate sub Text3_Change()
tax2.Text1 = Text3.Text
End Sub