1. 用c語言設計能夠完成多步四則運算的程序
多用計算器的構思及設計代碼
[關鍵詞]多用計算器;設計
數值計算可以說是日常最頻繁的工作了,WIN98提供了「計算器」軟體供用戶使用,該軟體可以處理一般的一步四則運算,例如:3+2、5/3等等,但在日常中用戶經常遇到多步四則運算問題,例如:3+4*5-4/2,45*34/2+18*7等等,那麼該個計算器就無法勝任了,作者製作了一個實用的計算器,該計算器新增不少功能:(程序界面如圖)
1.可以實現連續的四則運算
2.可以實現輸入式子的顯示
3.可以方便計算個人所得稅
4.滑鼠、鍵盤均可輸入數據
5.操作界面友好
6.擊鍵可發聲
構建該個計算器所需研究及解決的核心問題有如下幾個:1、連乘求值?2、字元顯示 3、鍵盤輸入?4、擊鍵發聲?5、個人所得稅法規,為了使大家對程序有更一步認識,現將代碼提供給讀者參考:
*定義數組及窗體變數
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
*調用名為「playsound」的API函數
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hMole As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME = &H20000?
Private Const SND_ASYNC = &H1?
Private Const SND_SYNC = &H0
*判斷通用過程
Sub pianan(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 pianan(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 pianan(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 pianan(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 "除數不能為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 pianan(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 pianan(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 pianan(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
另外,站長團上有產品團購,便宜有保證
2. c語言設計程序,要求如下。
#include <stdlib.h>
#include <conio.h>
void display()
{
int num = 0;
char c;
do
{
num++;
if (num >= 10)
{
return;
}
system("cls");
printf("這是第%d頁\n", num);
printf("按數字鍵跳到相關頁面\n");
printf("按任意鍵跳到下一頁\n");
c = getch();
if (c >= '1' && c <= '9')
{
num = c - '1';
}
}
while (1);
}
int main(int argc, char* argv[])
{
display();
return 0;
}
3. c語言怎麼實現四捨五入
# incloud <stdio>
int main(void)
{
float a ;
scanf(「%f」,&a);
a=(int)(a*1000+0.5)/1000.0;
printf (「%0.3f」,a);
return 0;
}
(3)c語言設計程序三舍四入擴展閱讀:
其他方法實現四捨五入:
int myround(double indata,int precision,double * outdata)
{
long pre = 1,i;
for(i = 0; i <precision; i ++)pre = pre * 10;
if(cy_FloatCompare(indata,0.00)> 0)
* outdata =(int)((indata * pre)+0.5)/100.00;
else
* outdata =(int)((indata * pre)-0.5)/100.00;
return 0;
}
// cy_FloatCompare是浮點數與0比較的函數,假設它存在。返回值與strcmp相同。
4. c語言 一個數 三舍四入 c語言,對一個數三舍四入
int function(float x)
{
if(x*10%10-3>0) return x*10/10+1;
else return x*10/10;
}
這是按小數點後第一位的三舍四入的。
5. 設計c語言程序(輸入三位數,分別輸出該數各個數位上的數字)
關鍵是把這個三位數分成三個數位上的單個數字,用除法運算和取余運算%來完成,關鍵幾句如下:
int x,a,b,c
x=423
c=x % 10餘數為3,得到個位上的數字
b=(x%100)/10說明:x%100得余數23,再利用兩個整數相除結果取整數商,得十位上的數字2
a=x/100得4 ,這還是利用了整數除法的特點
printf("a=%d b=%d c=%d",a,b,c)輸出a=4 b=2 c=3
希望對你有用
6. 用c語言設計程序,鍵盤輸入三個整數,輸出其中最小值。
#include<stdio.h>
intmain(){
inta,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%d ",(a<b?a:b)<c?(a<b?a:b):c);
return0;
}
7. C語言程序設計求助,求設計一個程序,要求輸入一個整數,然後將該整數倒序輸出,舉例:輸入1234輸出
1、c語言學校出來後就沒玩了,近期半年內吧,我准備再補補課。。。2、思路是可以設計一個數組,然後把數組調換過來。。。3、當然,如果你要求的數過於長,可能這個數據就比較長。同時,你還可以考慮「棧」,好像是先進後出吧,便於你編程。
8. C語言程序設計 程序3 4求解 要過程 謝謝!
應該是要每一步的輸出吧??分步解答最後輸出解果是怎麼來的?
上面程序:
main()裡面b屬於{1,2 , 3 , 4 , 5},分別將五個b代入row()
接下來分析row()
我們可以看出row()裡面的b始終是小於n的,這里的n我們是從主函數main傳過來的,也就是外部的b,所以row裡面的b小於等於main裡面的b,row裡面的b初始值是1,所以當main裡面的b等於1,row裡面的b就小於等於1,也就是1;懶得打字了,上圖,