當前位置:首頁 » 編程軟體 » 編程求序列

編程求序列

發布時間: 2022-05-08 22:13:28

A. 編程題求序列1,2,2,3,3,3,4,4,4,4,……中第100項的值

python">#-*-coding:utf-8-*-
"""仔細觀察數列,每個數字出現次數與自身值相等,且每次遞增1"""
i=1
count=0#控制循環次數
whileTrue:
forjinrange(0,i):
count+=1
ifcount==100:#如果已經到了第100項,沒必要繼續循環,跳出內層循環
break
ifcount==100:#如果是到達100次,跳出外層循環,列印此時i值即可
break
else:
i=i+1
print"the100thnumberis:",i

B. 求C語言編程答案 題 如下 求序列1,1,2,3,5,8,13,21.....的第100項的值。

這個可以用遞歸做!int mothd(int n) {if(n<=0)return 0;if((n==1)||(n==2))return n;return mothd(n-1)+nothd(n-2); }其中參數n為所求項數,如要得到第100項的值 直接調用 int number=mothd(100);就可以了

C. 編程,求序列1,5,6,11,17……的第10項的值

我用最簡單的吧:
首先,觀察前幾個數的規律,從第三個開始就是前兩項相加的和,所以設出前兩項A和前一項B

a=1 ……賦初值
b=5 ……賦初值
for i=1 to 8 ……強兩項已經有了,再循環八次就是第十項了
x=a+b ……設置一個數,是前兩項相加之和
a=b ……A變成原來的第二項
b=x ……B變成現在的求出的數,作為下一個循環的加數
next i ……結束循環
msgbox "第十項是:" & x ……最後輸出結果,我最近一直用SQL,所以用的是消息框輸 出,你按照情況輸出就可以了

D. C語言:n個編號為1~n的人圍坐一圈,從1號開始正向報數到m者退出,從下一人繼續;求出列序列,咋編程

代碼文本:

#include "stdio.h"

int main(int argc,char *argv[]){

int a[20],b[20],i,j,t,n,m;

printf("Enter n(int 0<n,m<21)... n m = ");

if(scanf("%d%d",&n,&m)==2 && n>0 && n<21 && m>0 && m<21){

for(i=0;i<n;a[i++]=i+1);//創建人員編號

i=-1,j=t=0;

printf(" The result is: ");

while(t<n)

if(a[++i%=n] && (++j%=m)==0){

printf("%d ",b[t++]=a[i]);//生成並輸出序列

a[i]=0;

}

putchar(' ');

}

else

puts("ERROR");

return 0;

}

供參考……

E. 要求編寫程序,計算序列 1 - 1/4 + 1/7 - 1/10 + ... 的前N項之和。

增加一個變數,用於取反,即可。

#include<stdio.h>

int main(){

int n,i,flag=1;

double sum=0;

printf("請輸入數字n:");

scanf("%d",&n);

for(i=1;i<=n;i++,flag*=-1){

sum+=1.0/(3*i-2)*flag;}

printf("sun=%.3f ",sum);

return 0;

}

(5)編程求序列擴展閱讀:

ln(1+x) = x - x^2/2 + x^3/3 - ...

Euler(歐拉)在1734年,利用Newton的成果,首先獲得了調和級數有限多項和的值。結果是:

1+1/2+1/3+1/4+...+1/n= ln(n+1)+r(r為常量)

證明是這樣的:

根據Newton的冪級數有:

ln(1+1/x) = 1/x - 1/2x^2 + 1/3x^3 - ...

於是:

1/x = ln((x+1)/x) + 1/2x^2 - 1/3x^3 + ...

代入x=1,2,...,n,就給出:

1/1 = ln(2) + 1/2 - 1/3 + 1/4 -1/5 + ...

1/2 = ln(3/2) + 1/2*4 - 1/3*8 + 1/4*16 - ...

F. C語言編程 求序列前N項和

2/1+3/2+5/3+8/5+...這個數列每項的分子、分母分別是Fibonacci數列的後一項與前一項。求這一數列前N項的和可採取N由鍵盤輸入,設一循環按Fibonacci數列規律求出分子與分母,將將分式轉換為浮點除法求值累加獲得最後結果。舉例代碼如下:

#include"stdio.h"
intmain(intargc,char*argv[]){
inta,b,i,N;
doubles;
printf("InputN(int0<N<44)... N=");//大於43時int范圍溢出
if(scanf("%d",&N)!=1||N<1||N>43){//保證輸入正確
printf("Inputerror,exit... ");
return0;
}
for(s=0.0,a=2,b=i=1;i<=N;i++){//由此循環計算
s+=a/(b+0.0);//當前項累加給s
a+=b;//下一項的分子是當前項分子分母之和
b=a-b;//下一項分母是當前項分子
}
printf("Theresultare%.2f(whenN=%d) ",s,N);
return0;
}

試運行結果如下圖:

G. 編程求序列1,1,2,,5,8,13,21……的第20項的值。。。用循環結構。。

public class Test1 {
//遞歸
public int f(int n){
if(n==1 || n==2){
return 1;
}else{
return f(n-2)+f(n-1);
}
}
//循環
public int f2(int num){
int valueNum = 0;
int a=1;
int b=1;
for(int i=1;i<=num;i++){
if(i ==1 || i == 2){
valueNum =1;
}else{
valueNum=a+b;
a=b;
b=valueNum;
}
}
return valueNum;
}

public static void main(String[] args) {
System.out.println(new Test1().f(20));
System.out.println(new Test1().f2(20));

}
}

H. java 編程 序列號

//哎....

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import javax.swing.*;
import javax.swing.text.MaskFormatter;

public class CodeTest extends JFrame {
private static final long serialVersionUID = 1L;
private JFormattedTextField formatField = null;
private JButton ba = null;
private String pattern = "AAAAA-AAAAA-AAAAA-AAAAA";
private JLabel code = new JLabel("注冊碼: ");
private JLabel input = new JLabel("序列號: ");
private JTextField codeField = new JTextField();
private JLabel rel = new JLabel();

public CodeTest(){
init();
}

public void init(){
MaskFormatter mft = CodeTest.getFormatter(pattern);
mft.setPlaceholderCharacter('X');
formatField = new JFormattedTextField();
formatField = new JFormattedTextField();
mft.install(formatField);
this.setBounds(200, 200, 240, 240);
this.setResizable(false);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
formatField.setBounds(30, 30, 180, 25);
ba = new JButton("注冊");
ba.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(formatField.getText().length() >= 1) {

}
String text = formatField.getText();
long vlong = getCode(text);
code.setText("注冊碼: (" + vlong + ")");
if((vlong + "").equals(codeField.getText())){
rel.setText("注冊成功!");
System.exit(0);
} else {
rel.setText("注冊失敗!");
}
}
});
codeField.setBounds(30, 85, 180, 25);
code.setBounds(30, 60, 180, 25);
ba.setBounds(30, 125, 180, 25);
rel.setBounds(30, 155, 100, 25);
input.setForeground(Color.RED);
code.setForeground(Color.RED);
rel.setForeground(Color.RED);
input.setBounds(30, 5, 100, 25);
this.add(rel);
this.add(codeField);
this.add(input);
this.add(code);
this.add(ba);
this.add(formatField);
ba.setDefaultCapable(true);

this.setVisible(true);
}

public static void main(String[] args) {
new CodeTest();

}

public static MaskFormatter getFormatter(String pattern){
try {
return new MaskFormatter(pattern);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}

public long getCode(String text){
char [] chs = text.toCharArray();
long vlong = 0;
for(char c: chs){
if(c != '-'){
vlong += 199 * (int)c;
}
}
return vlong;
}

}

I. 編程求任意兩個數字序列疊加時應注意什麼

對時域信號f (t )。
如果令取樣信號通過低通濾波器,該濾波器的截止頻率等於原信 號頻率的最高頻率,那麼取樣信號中大於原信號最高頻率的頻率 成分被濾去,而僅存原信號頻譜的頻率成分,這樣低通濾波器的 輸出為得到恢復的原信號。
抽樣定理是模擬信號數字化傳輸的理論基礎 ,它告訴我們: 如果對某一帶寬的有限時間連續信號 (模擬信號) 進行抽樣 ,且在抽樣率達到一定數值時, 根據這些抽樣值可以在接收端准確地恢復原信號 .也就是說 ,要傳輸模擬信號不一定傳輸模擬信號本身, 只需傳輸按抽樣定理得到的抽樣值就可以了。

熱點內容
解壓體育館 發布:2025-05-13 21:27:48 瀏覽:263
哪家編程課 發布:2025-05-13 21:27:04 瀏覽:895
為什麼文件要壓縮 發布:2025-05-13 21:16:07 瀏覽:50
區域網怎麼搭建校時伺服器 發布:2025-05-13 21:11:32 瀏覽:677
存儲器讀寫實驗心得 發布:2025-05-13 21:09:23 瀏覽:15
派派手機如何設置密碼 發布:2025-05-13 21:08:02 瀏覽:774
獄辱實驗棟第2集在線ftp 發布:2025-05-13 21:02:06 瀏覽:11
安卓桌面應用如何變大 發布:2025-05-13 20:59:39 瀏覽:361
解壓通知單有什麼用 發布:2025-05-13 20:58:37 瀏覽:567
俄羅斯方塊的編程 發布:2025-05-13 20:51:08 瀏覽:611