1.如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能
2.Cè¯è¨ç»¼å设计
3.python开方函数怎么写
4.数学开方
如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能
用记事本把这段代码复制过去,中药中药然后另存为.frm就可以了VERSION 5.
Begin VB.Form frmMain
Appearance = 0 'Flat
BackColor = &H&
BorderStyle = 3 'Fixed Dialog
Caption = "简单计算器"
ClientHeight =
ClientLeft =
ClientTop =
ClientWidth =
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight =
ScaleWidth =
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command
Caption = "^"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.PictureBox picDisplay
Appearance = 0 'Flat
BackColor = &H&
ForeColor = &H&
Height =
Left =
ScaleHeight =
ScaleWidth =
TabIndex =
Top =
Width =
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BorderStyle = 0 'None
Height =
Left =
Locked = -1 'True
TabIndex =
Top = 0
Width =
End
Begin VB.Label lblOperation
Appearance = 0 'Flat
BackColor = &H&
ForeColor = &H&
Height =
Left =
TabIndex =
Top = 0
Width =
End
End
Begin VB.CommandButton Command9
Caption = "退格"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command8
Caption = "清零"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton cmdDot
Caption = "."
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command7
Caption = "Sqrt"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command6
Caption = "="
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command5
Caption = "/"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command4
Caption = "*"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command3
Caption = "-"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command2
Caption = "+"
Height =
Left =
TabIndex =
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "9"
Height =
Index = 9
Left =
TabIndex = 9
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "8"
Height =
Index = 8
Left =
TabIndex = 8
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "7"
Height =
Index = 7
Left =
TabIndex = 7
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "6"
Height =
Index = 6
Left =
TabIndex = 6
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "5"
Height =
Index = 5
Left =
TabIndex = 5
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "4"
Height =
Index = 4
Left =
TabIndex = 4
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "3"
Height =
Index = 3
Left =
TabIndex = 3
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "2"
Height =
Index = 2
Left =
TabIndex = 2
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "1"
Height =
Index = 1
Left =
TabIndex = 1
Top =
Width =
End
Begin VB.CommandButton Command1
Caption = "0"
Height =
Index = 0
Left =
TabIndex = 0
Top =
Width =
End
End
Attribute VB_Name = "frmmain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Data As Double
Private lOperation As Long
Private fClear As Boolean
Private Sub cmdDot_Click()
If InStr(1,开方开方 Text1.Text, ".") <= 0 Then Text1.Text = Text1.Text & "."
End Sub
Private Sub Command1_Click(Index As Integer)
If fClear = True Then Text1.Text = "": fClear = False
Text1.Text = Text1.Text & Index
End Sub
Private Sub Command_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 5
lblOperation.Caption = "^"
End Sub
Private Sub Command2_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 1
lblOperation.Caption = "+"
End Sub
Private Sub Command3_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 2
lblOperation.Caption = "-"
End Sub
Private Sub Command4_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 3
lblOperation.Caption = "*"
End Sub
Private Sub Command5_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 4
lblOperation.Caption = "/"
End Sub
Private Sub Command6_Click()
If fClear = False Then
Select Case lOperation
Case 0
Case 1: Text1.Text = Data + Val(Text1.Text)
Case 2: Text1.Text = Data - Val(Text1.Text)
Case 3: Text1.Text = Data * Val(Text1.Text)
Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)
Case 5: Text1.Text = Data ^ Val(Text1.Text)
End Select
End If
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command7_Click()
If Val(Text1.Text) <= 0 Then MsgBox "开方数大于等于0"
Text1.Text = Sqr(Val(Text1.Text))
Data = Val(Text1.Text)
fClear = True
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command8_Click()
Text1.Text = ""
lOperation = 0
lblOperation.Caption = ""
End Sub
Private Sub Command9_Click()
If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0"): Command1_Click 0
Case Asc("1"): Command1_Click 1
Case Asc("2"): Command1_Click 2
Case Asc("3"): Command1_Click 3
Case Asc("4"): Command1_Click 5
Case Asc("5"): Command1_Click 4
Case Asc("6"): Command1_Click 6
Case Asc("7"): Command1_Click 7
Case Asc("8"): Command1_Click 8
Case Asc("9"): Command1_Click 9
Case Asc("."): cmdDot_Click
Case Asc("+"): Command2_Click
Case Asc("-"): Command3_Click
Case Asc("*"): Command4_Click
Case Asc("/"): Command5_Click
Case Asc("^"): Command_Click
Case Asc("s"): Command7_Click
Case Asc("S"): Command7_Click
Case vbKeyBack: Command9_Click
Case Asc("`"): Command8_Click
Case Asc("="): Command6_Click
Case : Command6_Click
End Select
KeyAscii = 0
End Sub
Cè¯è¨ç»¼å设计
å¦æ对楼主æ帮å©ï¼ç»ä¸ªé纳好ä¸ï¼è°¢è°¢å¦1.ç¨åºåæï¼å¯å¡«å¨ç¾ä½ãåä½ã个ä½çæ°åé½æ¯1ã2ã3ã4ãç»æææçæåååå»
æä¸æ»¡è¶³æ¡ä»¶çæåã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j,k;
printf("\n");
for(i=1;i<5;i++) /*以ä¸ä¸ºä¸é循ç¯*/
for(j=1;j<5;j++)
for (k=1;k<5;k++)
{
if (i!=k&&i!=j&&j!=k) /*ç¡®ä¿iãjãkä¸ä½äºä¸ç¸å*/
printf("%d,%d,%d\n",i,j,k);
}
getch();
}
==============================================================
ãç¨åº2ã
é¢ç®ï¼ä¼ä¸åæ¾çå¥éæ ¹æ®å©æ¶¦ææãå©æ¶¦(I)ä½äºæçäºä¸å æ¶ï¼å¥éå¯æ%ï¼å©æ¶¦é«
äºä¸å ï¼ä½äºä¸å æ¶ï¼ä½äºä¸å çé¨åæ%ææï¼é«äºä¸å çé¨åï¼å¯å¯æ
æ7.5%ï¼ä¸å°ä¸ä¹é´æ¶ï¼é«äºä¸å çé¨åï¼å¯ææ5%ï¼ä¸å°ä¸ä¹é´æ¶é«äº
ä¸å çé¨åï¼å¯ææ3%ï¼ä¸å°ä¸ä¹é´æ¶ï¼é«äºä¸å çé¨åï¼å¯ææ1.5%ï¼é«äº
ä¸å æ¶ï¼è¶ è¿ä¸å çé¨åæ1%ææï¼ä»é®çè¾å ¥å½æå©æ¶¦Iï¼æ±åºåæ¾å¥éæ»æ°ï¼
1.ç¨åºåæï¼è¯·å©ç¨æ°è½´æ¥åçï¼å®ä½ã注æå®ä¹æ¶éæå¥éå®ä¹æé¿æ´åããããããã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
long int i;
int bonus1,bonus2,bonus4,bonus6,bonus,bonus;
scanf("%ld",&i);
bonus1=*0. 1;
bonus2=bonus1+*0.;
bonus4=bonus2+*0.5;
bonus6=bonus4+*0.3;
bonus=bonus6+*0.;
if(i<=)
bonus=i*0.1;
else if(i<=)
bonus=bonus1+(i-)*0.;
else if(i<=)
bonus=bonus2+(i-)*0.;
else if(i<=)
bonus=bonus4+(i-)*0.;
else if(i<=)
bonus=bonus6+(i-)*0.;
else
bonus=bonus+(i-)*0.;
printf("bonus=%d",bonus);
getch();
}
==============================================================
ãç¨åº3ã
é¢ç®ï¼ä¸ä¸ªæ´æ°ï¼å®å ä¸åæ¯ä¸ä¸ªå®å ¨å¹³æ¹æ°ï¼åå ä¸åæ¯ä¸ä¸ªå®å ¨å¹³æ¹æ°ï¼è¯·é®è¯¥æ°æ¯å¤å°ï¼
1.ç¨åºåæï¼å¨ä¸ä»¥å å¤æï¼å å°è¯¥æ°å ä¸ååå¼æ¹ï¼åå°è¯¥æ°å ä¸ååå¼æ¹ï¼å¦æå¼æ¹å
çç»æ满足å¦ä¸æ¡ä»¶ï¼å³æ¯ç»æã请çå ·ä½åæï¼
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "math.h"
#include "stdio.h"
#include "conio.h"
main()
{
long int i,x,y,z;
for (i=1;i<;i++)
{
x=sqrt(i+); /*x为å ä¸åå¼æ¹åçç»æ*/
y=sqrt(i+); /*y为åå ä¸åå¼æ¹åçç»æ*/
if(x*x==i+&&y*y==i+) /*å¦æä¸ä¸ªæ°çå¹³æ¹æ ¹çå¹³æ¹çäºè¯¥æ°ï¼è¿è¯´ææ¤æ°æ¯å®å ¨å¹³æ¹æ°*/
printf("\n%ld\n",i);
}
getch();
}
==============================================================
ãç¨åº4ã
é¢ç®ï¼è¾å ¥æå¹´ææææ¥ï¼å¤æè¿ä¸å¤©æ¯è¿ä¸å¹´ç第å 天ï¼
1.ç¨åºåæï¼ä»¥3æ5æ¥ä¸ºä¾ï¼åºè¯¥å æå两个æçå èµ·æ¥ï¼ç¶ååå ä¸5天å³æ¬å¹´ç第å 天ï¼ç¹æ®
æ åµï¼é°å¹´ä¸è¾å ¥æ份大äº3æ¶éèèå¤å ä¸å¤©ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int day,month,year,sum,leap;
printf("\nplease input year,month,day\n");
scanf("%d,%d,%d",&year,&month,&day);
switch(month) /*å 计ç®ææ以åæ份çæ»å¤©æ°*/
{
case 1:sum=0;break;
case 2:sum=;break;
case 3:sum=;break;
case 4:sum=;break;
case 5:sum=;break;
case 6:sum=;break;
case 7:sum=;break;
case 8:sum=;break;
case 9:sum=;break;
case :sum=;break;
case :sum=;break;
case :sum=;break;
default:printf("data error");break;
}
sum=sum+day; /*åå ä¸æ天ç天æ°*/
if(year%==0||(year%4==0&&year%!=0)) /*å¤ææ¯ä¸æ¯é°å¹´*/
leap=1;
else
leap=0;
if(leap==1&&month>2) /*å¦ææ¯é°å¹´ä¸æ份大äº2,æ»å¤©æ°åºè¯¥å ä¸å¤©*/
sum++;
printf("It is the %dth day.",sum);
getch();
}
==============================================================
ãç¨åº5ã
é¢ç®ï¼è¾å ¥ä¸ä¸ªæ´æ°x,y,zï¼è¯·æè¿ä¸ä¸ªæ°ç±å°å°å¤§è¾åºã
1.ç¨åºåæï¼æ们æ³åæ³ææå°çæ°æ¾å°xä¸ï¼å å°xä¸yè¿è¡æ¯è¾ï¼å¦æx>yåå°xä¸yçå¼è¿è¡äº¤æ¢ï¼
ç¶ååç¨xä¸zè¿è¡æ¯è¾ï¼å¦æx>zåå°xä¸zçå¼è¿è¡äº¤æ¢ï¼è¿æ ·è½ä½¿xæå°ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int x,y,z,t;
scanf("%d%d%d",&x,&y,&z);
if (x>y)
{ t=x;x=y;y=t;} /*交æ¢x,yçå¼*/
if(x>z)
{ t=z;z=x;x=t;} /*交æ¢x,zçå¼*/
if(y>z)
{ t=y;y=z;z=t;} /*交æ¢z,yçå¼*/
printf("small to big: %d %d %d\n",x,y,z);
getch();
}
==============================================================
ãç¨åº6ã
é¢ç®ï¼ç¨*å·è¾åºåæ¯Cçå¾æ¡ã
1.ç¨åºåæï¼å¯å ç¨'*'å·å¨çº¸ä¸ååºåæ¯Cï¼ååè¡è¾åºã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
printf("Hello C-world!\n");
printf(" ****\n");
printf(" *\n");
printf(" * \n");
printf(" ****\n");
getch();
}
==============================================================
ãç¨åº7ã
é¢ç®ï¼è¾åºç¹æ®å¾æ¡ï¼è¯·å¨cç¯å¢ä¸è¿è¡ï¼çä¸çï¼Very Beautiful!
1.ç¨åºåæï¼åç¬¦å ±æ个ãä¸åå符ï¼å¾å½¢ä¸ä¸æ ·ããããããã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
char a=,b=;
printf("%c%c%c%c%c\n",b,a,a,a,b);
printf("%c%c%c%c%c\n",a,b,a,b,a);
printf("%c%c%c%c%c\n",a,a,b,a,a);
printf("%c%c%c%c%c\n",a,b,a,b,a);
printf("%c%c%c%c%c\n",b,a,a,a,b);
getch();
}
==============================================================
ãç¨åº8ã
é¢ç®ï¼è¾åº9*9å£è¯ã
1.ç¨åºåæï¼åè¡ä¸åèèï¼å ±9è¡9åï¼iæ§å¶è¡ï¼jæ§å¶åã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j,result;
printf("\n");
for (i=1;i<;i++)
{
for(j=1;j<;j++)
{
result=i*j;
printf("%d*%d=%-3d",i,j,result); /*-3d表示左对é½ï¼å 3ä½*/
}
printf("\n"); /*æ¯ä¸è¡åæ¢è¡*/
}
getch();
}
==============================================================
ãç¨åº9ã
é¢ç®ï¼è¦æ±è¾åºå½é 象æ£æ£çã
1.ç¨åºåæï¼ç¨iæ§å¶è¡ï¼jæ¥æ§å¶åï¼æ ¹æ®i+jçåçååæ¥æ§å¶è¾åºé»æ¹æ ¼ï¼è¿æ¯ç½æ¹æ ¼ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
if((i+j)%2==0)
printf("%c%c",,);
else
printf(" ");
printf("\n");
}
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼æå°æ¥¼æ¢¯ï¼åæ¶å¨æ¥¼æ¢¯ä¸æ¹æå°ä¸¤ä¸ªç¬è¸ã
1.ç¨åºåæï¼ç¨iæ§å¶è¡ï¼jæ¥æ§å¶åï¼jæ ¹æ®içååæ¥æ§å¶è¾åºé»æ¹æ ¼ç个æ°ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j;
printf("\1\1\n"); /*è¾åºä¸¤ä¸ªç¬è¸*/
for(i=1;i<;i++)
{
for(j=1;j<=i;j++)
printf("%c%c",,);
printf("\n");
}
getch();
}
ãç¨åºã
é¢ç®ï¼å¤å ¸é®é¢ï¼æä¸å¯¹å åï¼ä»åºçå第3个æèµ·æ¯ä¸ªæé½çä¸å¯¹å åï¼å°å åé¿å°ç¬¬ä¸ä¸ªæ
åæ¯ä¸ªæåçä¸å¯¹å åï¼åå¦å åé½ä¸æ»ï¼é®æ¯ä¸ªæçå åæ»æ°ä¸ºå¤å°ï¼
1.ç¨åºåæï¼ãå åçè§å¾ä¸ºæ°å1,1,2,3,5,8,,....
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
long f1,f2;
int i;
f1=f2=1;
for(i=1;i<=;i++)
{
printf("%ld %ld",f1,f2);
if(i%2==0) printf("\n"); /*æ§å¶è¾åºï¼æ¯è¡å个*/
f1=f1+f2; /*å两个æå èµ·æ¥èµå¼ç»ç¬¬ä¸ä¸ªæ*/
f2=f1+f2; /*å两个æå èµ·æ¥èµå¼ç»ç¬¬ä¸ä¸ªæ*/
}
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼å¤æ-ä¹é´æå¤å°ä¸ªç´ æ°ï¼å¹¶è¾åºææç´ æ°ã
1.ç¨åºåæï¼å¤æç´ æ°çæ¹æ³ï¼ç¨ä¸ä¸ªæ°åå«å»é¤2å°sqrt(è¿ä¸ªæ°)ï¼å¦æè½è¢«æ´é¤ï¼
å表ææ¤æ°ä¸æ¯ç´ æ°ï¼åä¹æ¯ç´ æ°ã ãããããã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
#include "math.h"
main()
{
int m,i,k,h=0,leap=1;
printf("\n");
for(m=;m<=;m++)
{
k=sqrt(m+1);
for(i=2;i<=k;i++)
if(m%i==0)
{
leap=0;
break;
}
if(leap)
{
printf("%-4d",m);
h++;
if(h%==0)
printf("\n");
}
leap=1;
}
printf("\nThe total is %d",h);
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼æå°åºææçâæ°´ä»è±æ°âï¼æè°âæ°´ä»è±æ°âæ¯æä¸ä¸ªä¸ä½æ°ï¼å ¶åä½æ°åç«æ¹åçäºè¯¥æ°
æ¬èº«ãä¾å¦ï¼æ¯ä¸ä¸ªâæ°´ä»è±æ°âï¼å 为=1çä¸æ¬¡æ¹ï¼5çä¸æ¬¡æ¹ï¼3çä¸æ¬¡æ¹ã
1.ç¨åºåæï¼å©ç¨for循ç¯æ§å¶-个æ°ï¼æ¯ä¸ªæ°å解åºä¸ªä½ï¼åä½ï¼ç¾ä½ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int i,j,k,n;
printf("'water flower'number is:");
for(n=;n<;n++)
{
i=n/;/*å解åºç¾ä½*/
j=n/%;/*å解åºåä½*/
k=n%;/*å解åºä¸ªä½*/
if(i*+j*+k==i*i*i+j*j*j+k*k*k)
printf("%-5d",n);
}
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼å°ä¸ä¸ªæ£æ´æ°å解质å æ°ãä¾å¦ï¼è¾å ¥,æå°åº=2*3*3*5ã
ç¨åºåæï¼å¯¹nè¿è¡å解质å æ°ï¼åºå æ¾å°ä¸ä¸ªæå°çè´¨æ°kï¼ç¶åæä¸è¿°æ¥éª¤å®æï¼
(1)å¦æè¿ä¸ªè´¨æ°æ°çäºnï¼å说æå解质å æ°çè¿ç¨å·²ç»ç»æï¼æå°åºå³å¯ã
(2)å¦æn<>kï¼ä½nè½è¢«kæ´é¤ï¼ååºæå°åºkçå¼ï¼å¹¶ç¨né¤ä»¥kçå,ä½ä¸ºæ°çæ£æ´æ°ä½ n,
éå¤æ§è¡ç¬¬ä¸æ¥ã
(3)å¦ænä¸è½è¢«kæ´é¤ï¼åç¨k+1ä½ä¸ºkçå¼,éå¤æ§è¡ç¬¬ä¸æ¥ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
/* zheng int is divided yinshu*/
#include "stdio.h"
#include "conio.h"
main()
{
int n,i;
printf("\nplease input a number:\n");
scanf("%d",&n);
printf("%d=",n);
for(i=2;i<=n;i++)
while(n!=i)
{
if(n%i==0)
{
printf("%d*",i);
n=n/i;
}
else
break;
}
printf("%d",n);
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼å©ç¨æ¡ä»¶è¿ç®ç¬¦çåµå¥æ¥å®ææ¤é¢ï¼å¦ä¹ æ绩>=åçåå¦ç¨A表示ï¼-åä¹é´çç¨B表示ï¼
å以ä¸çç¨C表示ã
1.ç¨åºåæï¼(a>b)?a:bè¿æ¯æ¡ä»¶è¿ç®ç¬¦çåºæ¬ä¾åã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int score;
char grade;
printf("please input a score\n");
scanf("%d",&score);
grade=score>=?'A':(score>=?'B':'C');
printf("%d belongs to %c",score,grade);
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼è¾å ¥ä¸¤ä¸ªæ£æ´æ°månï¼æ±å ¶æå¤§å ¬çº¦æ°åæå°å ¬åæ°ã
1.ç¨åºåæï¼å©ç¨è¾é¤æ³ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int a,b,num1,num2,temp;
printf("please input two numbers:\n");
scanf("%d,%d",&num1,&num2);
if(num1<num2)/*交æ¢ä¸¤ä¸ªæ°ï¼ä½¿å¤§æ°æ¾å¨num1ä¸*/
{
temp=num1;
num1=num2;
num2=temp;
}
a=num1;b=num2;
while(b!=0)/*å©ç¨è¾é¤æ³ï¼ç´å°b为0为æ¢*/
{
temp=a%b;
a=b;
b=temp;
}
printf("gongyueshu:%d\n",a);
printf("gongbeishu:%d\n",num1*num2/a);
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼è¾å ¥ä¸è¡å符ï¼åå«ç»è®¡åºå ¶ä¸è±æåæ¯ãç©ºæ ¼ãæ°ååå ¶å®å符ç个æ°ã
1.ç¨åºåæï¼å©ç¨whileè¯å¥,æ¡ä»¶ä¸ºè¾å ¥çå符ä¸ä¸º'\n'.
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
char c;
int letters=0,space=0,digit=0,others=0;
printf("please input some characters\n");
while((c=getchar())!='\n')
{
if(c>='a'&&c<='z'||c>='A'&&c<='Z')
letters++;
else if(c==' ')
space++;
else if(c>='0'&&c<='9')
digit++;
else
others++;
}
printf("all in all:char=%d space=%d digit=%d others=%d\n",letters,
space,digit,others);
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼æ±s=a+aa+aaa+aaaa+aa...açå¼ï¼å ¶ä¸aæ¯ä¸ä¸ªæ°åãä¾å¦2++++(æ¤æ¶
å ±æ5个æ°ç¸å )ï¼å 个æ°ç¸å æé®çæ§å¶ã
1.ç¨åºåæï¼å ³é®æ¯è®¡ç®åºæ¯ä¸é¡¹çå¼ã
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
int a,n,count=1;
long int sn=0,tn=0;
printf("please input a and n\n");
scanf("%d,%d",&a,&n);
printf("a=%d,n=%d\n",a,n);
while(count<=n)
{
tn=tn+a;
sn=sn+tn;
a=a*;
++count;
}
printf("a+aa+...=%ld\n",sn);
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼ä¸ä¸ªæ°å¦ææ°å¥½çäºå®çå åä¹åï¼è¿ä¸ªæ°å°±ç§°ä¸ºâå®æ°âãä¾å¦6=1ï¼2ï¼3.ç¼ç¨
æ¾åºä»¥å çææå®æ°ã
1. ç¨åºåæï¼è¯·åç §ç¨åº<--ä¸é¡µç¨åº.
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "conio.h"
main()
{
static int k[];
int i,j,n,s;
for(j=2;j<;j++)
{
n=-1;
s=j;
for(i=1;i<j;i++)
{
if((j%i)==0)
{
n++;
s=s-i;
k[n]=i;
}
}
if(s==0)
{
printf("%d is a wanshu",j);
for(i=0;i<n;i++)
printf("%d,",k);
printf("%d\n",k[n]);
}
}
getch();
}
==============================================================
ãç¨åºã
é¢ç®ï¼ä¸çä»ç±³é«åº¦èªç±è½ä¸ï¼æ¯æ¬¡è½å°ååè·³ååé«åº¦çä¸åï¼åè½ä¸ï¼æ±å®å¨
第次è½å°æ¶ï¼å ±ç»è¿å¤å°ç±³ï¼ç¬¬æ¬¡åå¼¹å¤é«ï¼
1.ç¨åºåæï¼è§ä¸é¢æ³¨é
2.ç¨åºæºä»£ç ï¼
å¤å¶ä»£ç 代ç å¦ä¸:
#include "stdio.h"
#include "stdio.h"
main()
{
float sn=.0,hn=sn/2;
int n;
for(n=2;n<=;n++)
{
sn=sn+2*hn;/*第n次è½å°æ¶å ±ç»è¿çç±³æ°*/
hn=hn/2; /*第n次åè·³é«åº¦*/
}
printf("the total of road is %f\n",sn);
printf("the tenth is %f meter\n",hn);
getch();
}
python开方函数怎么写
python开方函数写法是将某个数乘以0.5次方、使用内置库math、源码长除式算法。中药中药1、开方开方将某个数乘以0.5次方
将某个数乘以0.5次方也是源码pomelo 棋牌游戏源码python开平方中最简单的一种方式,具体为:使用内置函数pow():pow(x,中药中药0.5),其中x为要开平方的开方开方数。
2、源码使用内置库math
使用内置库math的中药中药sqrt()函数可以开平方,例如:import math,开方开方#开平方,源码result=math.sqrt(9),中药中药print(result)#输出3.0。开方开方
3、源码网页方块选项源码长除式算法
Python的“长除式算法”开方法是一种迭代法,它使用一个称为“长除式”的数学表达式来计算平方根。长除式如下:Xn+1=(Xn+a/Xn)/2,其中,Xn是第n次迭代的结果,a是要开方的数字。
这个算法的发卡网源码如何原理是,假设一个数的平方根为X,那么X的平方为a。令Xn为第n次迭代的结果,则Xn的平方为Xn*Xn=Xn*Xn=(Xn+a/Xn)/2*(Xn+a/Xn)/2=a。因此,Xn+1=(Xn+a/Xn)/2,即Xn+1的app im群聊源码平方为a。
由于Xn的平方为a,因此Xn+1的平方根为Xn+1。而Xn+1的平方根正是我们要求的数字a的平方根。因此,采用“长除式算法”,可以迭代求出任意正数的平方根。
python语言特点:
1、网址防举报源码可移植性
由于它的开源本质,Python已经被移植在许多平台上(经过改动使它能够工作在不同平台上)。这些平台包括Linux、Windows、FreeBSD、Macintosh、Solaris、OS/2、Amiga、AROS、以及Google基于linux开发的android平台。
2、解释性
一个用编译性语言比如C或C++写的程序可以从源文件(即C或C++语言)转换到一个你的计算机使用的语言(二进制代码,即0和1)。这个过程通过编译器和不同的标记、选项完成。运行程序的时候,连接/转载器软件把你的程序从硬盘复制到内存中并且运行。
而Python语言写的程序不需要编译成二进制代码。你可以直接从源代码运行程序。在计算机内部,Python解释器把源代码转换成称为字节码的中间形式,然后再把它翻译成计算机使用的机器语言并运行。这使得使用Python更加简单。也使得Python程序更加易于移植。
数学开方
#include <math.h>
main(void)
{ int a,b,c,d,e,f,g;float h,i,j,k,l;
for(a=1;a<;a++)
{ for(b=1;b<;b++)
if (b!=a)
{ for(c=1;c<;c++)
if (c!=b&c!=a)
{ for(d=1;d<;d++)
if (d!=a&d!=b&d!=c)
{ for (e=1;e<;e++)
if (e!=a&e!=b&e!=c&e!=d)
{ for(f=1;f<;f++)
if (f!=a&f!=b&f!=c&f!=d&f!=e)
g=(*a+*b+*c+*d+*e+f);
i=sqrt(g);j=floor(i/);k=(floor(i/)-floor(i/)*);l=(i-floor(i/)*);
h=sqrt(g)-floor(sqrt(g));
if (h==0)
if (j!=0&k!=0&l!=0)
if (j!=k&j!=l&k!=l)
if (j!=a&j!=b&j!=c&j!=d&j!=e&j!=f)
if (k!=a&k!=b&k!=c&k!=d&k!=e&k!=f)
if (l!=a&l!=b&l!=c&l!=d&l!=e&l!=f)
printf("%f,%f,%f,%d\n",j,k,l,g);}}}}}}
C源代码,输出是5,6,7,