當前位置:首頁 » 編程軟體 » 計算編程

計算編程

發布時間: 2022-01-23 00:57:00

1. c語言編程計算

#include<stdio.h>
#include<math.h>
int main()
{
double x, res = 0;
scanf("%lf", &x);
if (x < -1)
res = pow(x, 3) - 1;
if (x >= -1 && x <= 1)
res = (-3)*x + 1;
if (x > 1 && x <= 10)
res = 3*exp(2*x - 1) + 5;
if (x > 10)
res = 5*x + 3*log10(2*x*x - 1) - 13;
printf("res = %f\n", res);
return 0;
}
用gcc編譯時加上-lm

2. 一道計算編程題

思路大概是n個物品里拿出來所有單數的所以先判斷n是單數還是雙數
if(n%2==0){
//雙數就有一半是單數就是n裡面拿n/2個有多少種方法

n

}else{
}
這是最尷尬的思路已經出來了不會寫數學表達式

3. c語言編程計算!~急!!!!!!!!!

#include <stdio.h>
main()
{
int i,n;
int sum,prod;
float salary,total;

sum = 0;
i=0;
//求和
while(i<100)
{
sum += i;
i++;
}
printf("The sum from 1 to 100 is: %d\n",sum);

//輸入n求和
printf("Input n:");
scanf("%d",&n);

sum = 0;
i=0;
while(i<n)
{
sum += i;
i++;
}
printf("The sum from 1 to %d is: %d\n",n,sum);

//第2問
printf("Input n:");
scanf("%d",&n);
sum =0;
i=n;
while(i>=1)
{
sum += i;
i--;
}
printf("The sum from %d to 1 is: %d\n",n,sum);

//第3問
printf("Input n:");
scanf("%d",&n);

prod = 1;
while(i<=n)
{
prod *= i;
i++;
}
printf("The proct from 1 to %d: %d\n",n,prod);

//第4問
i=1;
while(i<=10)
{
printf("%d ",10*i);
i++;
}
printf("\n");

//第5問
total = 0;
i=1;
while(i<=12) {
printf("Enter the salary of month %d:",i);
scanf("%f",&salary);
total += salary;
i++;
}
printf("Total income: %.2f\n",total);
}

4. 編程計算數學表達式

//java MyEclipse 8.5
//the first
import java.util.*;class A{
public double a;
public double answer(){
a=1200/(24-4*5);
return a;
}
}
//the second
class B{
public double[]a=new double[2];
int i=0;
double e=0;

public double print(){
Scanner scan=new Scanner(System.in);
while(i<=1){
double d= scan.nextDouble();
a[i++]=d;
}
e=a[0]*a[0]+a[1]*a[1];
e=Math.sqrt(e);
return e;
}
}public class Text{
public static void main(String[] args){
A p=new A();
B q=new B();
System.out.println("The first answer is:"+p.answer());
System.out.println("The second answer is:"+q.print());
}
}運行結果The first answer is:300.0
1
2
The second answer is:2.23606797749979

5. 計算機編程計算

2.
S=0
For i=10 step 10
S=S+i
next i

其他的題目明顯超出計算機中整型數可表示的范圍,涉及復雜演算法,或者如果你使用的變成語言支持「大數」數據類型可以進行大數運算

6. 編程計算

我是用Java寫的,如下
class Main{
public Main(){}
public static void main(String agrs[])
{
int i,sum=0;
for(i=1;i<=1000;i++)
{
if(i % 3==0&i%7 ==0) //時被3和7整除
{
System.out.println(i);
sum+=i;
}
}
System.out.println("總和是:"+sum);
}

}

7. C語言計算編程(求大佬指點)

用c語言分別輸出個位十位和百位的數字,可以根據下面步驟進行,c語言作為一種程序代碼,因此在輸入時絕對不能弄錯任何符號。 1.#includevoid main(){ 2.int a,a0,a1,a2;scanf("%d",&a); 3.a2=a/100; /*確定x百位的數*/ 4.a1=(a-a2*100)/10; /*確定x十位數*/ 5.a0=a-a2*100-a1*10; /*確定x個位數*/ 6.printf("百十個位數分別為: 7.%d,%d,%d\n",a2,a1,a0);} 以上就是用c語言輸入一個三位數的步驟。

8. 計算器編程怎麼編

易語言高仿計算器源碼
-----------------------------------
版本
2
.程序集
窗口程序集1
.子程序
_按鈕1_被單擊
顯示框.加入文本
(「1」)
.子程序
_按鈕2_被單擊
顯示框.加入文本
(「2」)
.子程序
_按鈕3_被單擊
顯示框.加入文本
(「3」)
.子程序
_按鈕4_被單擊
顯示框.加入文本
(「4」)
.子程序
_按鈕5_被單擊
顯示框.加入文本
(「5」)
.子程序
_按鈕6_被單擊
顯示框.加入文本
(「6」)
.子程序
_按鈕7_被單擊
顯示框.加入文本
(「7」)
.子程序
_按鈕8_被單擊
顯示框.加入文本
(「8」)
.子程序
_按鈕9_被單擊
顯示框.加入文本
(「9」)
.子程序
_按鈕0_被單擊
顯示框.加入文本
(「0」)
.子程序
_按鈕點_被單擊
顯示框.內容

顯示框.內容

「.」
.子程序
_按鈕加_被單擊
第一個數.內容

顯示框.內容
符號框.內容

「+」
顯示框.內容

「」
.子程序
_按鈕減_被單擊
第一個數.內容

顯示框.內容
符號框.內容

「-」
顯示框.內容

「」
.子程序
_按鈕乘_被單擊
第一個數.內容

顯示框.內容
符號框.內容

「*」
顯示框.內容

「」
.子程序
_按鈕除_被單擊
第一個數.內容

顯示框.內容
符號框.內容

「/」
顯示框.內容

「」
.子程序
_按鈕等於_被單擊
.如果
(符號框.內容

「+」)
顯示框.內容

到文本
(到數值
(第一個數.內容)

到數值
(顯示框.內容))
.否則
.如果
(符號框.內容

「-」)
顯示框.內容

到文本
(到數值
(第一個數.內容)

到數值
(顯示框.內容))
.否則
.如果
(符號框.內容

「*」)
顯示框.內容

到文本
(到數值
(第一個數.內容)
×
到數值
(顯示框.內容))
.否則
.如果
(顯示框.內容

「0」)
.如果
(符號框.內容

「/」)
顯示框.內容

到文本
(到數值
(第一個數.內容)
÷
到數值
(顯示框.內容))
.否則
.如果結束
.否則
信息框
(「錯誤,被除數不能為
0
」,
0,
)
.如果結束
.如果結束
.如果結束
.如果結束
.子程序
_按鈕清空_被單擊
顯示框.內容

「」
.子程序
_按鈕清空_被雙擊,
邏輯型
.參數
橫向位置,
整數型
.參數
縱向位置,
整數型
.參數
功能鍵狀態,
整數型
第一個數.內容

「」

9. 計算器編程

這種東西網上一搜一大堆。

10. 數值計算編程

給你參考下吧

//牛頓下山法

//非線性方程求根

#include"iostream"
#include"stdlib.h"
#include"math.h"
#include"conio.h"
using namespace std;

double function(double x)
{
return x*x*x-x-1;
}

double function_(double x)
{
return 3*x*x-1;
}
void error_output(int p)
{
switch(p)
{
case 1:cout<<"超出下山次數,請另選擇初值!"<<endl;
case 2:cout<<"超出迭代次數,失敗!";
}

}

int main()
{

double x,e,l=1,x1;
int m,n,k=1,j;
cout<<"請輸入初值: ";
cin>>x;
cout<<"輸入精度: ";
cin>>e;
cout<<"輸入最大迭代次數 : ";
cin>>m;
cout<<"輸入最大下山次數: ";
cin>>n;

loop:
j=1;
if(function(x)==0){
cout<<"該初值就是方程的根!";
cout<<endl;
return 1;
}
x1=x-l*function(x)/function_(x);
for(l=1,j=1;j<=n&&k==1;j++)
{
x1=x-l*function(x)/function_(x);
if(fabs(function(x1))>fabs(function(x))){
l=l/2;
cout<<"x0 "<<x<<" x1 "<<x1<<endl;
}
else break;
}
for(l=1,j=1;j<=n&&k!=1;j++)
{
x1=x-l*function(x)/function_(x);
if(fabs(function(x1))>fabs(function(x))){
l=l/2;
cout<<"x0 "<<x<<" x1 "<<x1<<endl;
}
else break;
}
if(j>n)error_output(1);
if(fabs(x1-x)<e)cout<<"求得方程的根:"<<x1<<endl;
else{
if(k==m)error_output(2);
else {
k=k+1;
x=x1;
goto loop;
}
}
getch();
return 1;

}

熱點內容
編程畫櫻花 發布:2024-03-29 02:11:24 瀏覽:472
騰訊雲伺服器1mb老掉線 發布:2024-03-29 01:56:11 瀏覽:214
執行sql語句的存儲過程 發布:2024-03-29 01:52:37 瀏覽:696
婚紗攝影腳本 發布:2024-03-29 01:47:40 瀏覽:900
我的世界伺服器咋開外掛 發布:2024-03-29 01:07:45 瀏覽:455
sql寫報表 發布:2024-03-29 01:03:23 瀏覽:305
家用伺服器怎麼選 發布:2024-03-29 00:49:18 瀏覽:401
Ap6510dn如何配置 發布:2024-03-29 00:38:47 瀏覽:333
安卓和蘋果哪個更佔用內存 發布:2024-03-29 00:37:02 瀏覽:424
編譯錯誤算bug嗎 發布:2024-03-29 00:23:03 瀏覽:34