當前位置:首頁 » 編程軟體 » 關於數的編程

關於數的編程

發布時間: 2023-03-13 10:51:20

1. C語言編程,關於數組的應用

第(1)題:

#include<stdio.h>
voidmain(){
inti,a[18];
for(i=17;i>9;i--)
a[i]=i+1;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=17;i>=0;i--)
{
printf("%-3d",a[i]);
if((18-i)%5==0)
printf(" ");
}
}

2. java編程題 有趣的數

就你出的題來說,沒看懂,就java來說表示起始2,一直到N做循環
import java.util.Scanner;

public class FunNumber {

public static void main(String[] args) {
Scanner fin = new Scanner(System.in);
int N = fin.nextInt();

long i = (long)Math.pow(10, N-1);
long j = (long)Math.pow(10, N);
long count = 0;
for(;i<j;i++){
if(isFun(i,N)) {
count++;
System.out.println(i);
}
}
System.out.println("Count % 1000000007 = " + count%1000000007);

}
public static boolean isFun(long num,int N){
boolean[] num_exist = new boolean[4];

for(;N>0;N--){
int i = (int)(num%Math.pow(10,N)/Math.pow(10,N-1));
switch(i){
case 0:
num_exist[0] = true;
//0必須都在1前
if(num_exist[1]){
return false;
}
break;
case 1:
num_exist[1] = true;
break;
case 2:
num_exist[2] = true;
//2必須都在3前
if(num_exist[3]){
return false;
}
break;
case 3:
num_exist[3] = true;
break;
default:
//不只包含0123
return false;
}

}
//0123至少出現1次
if(num_exist[0]&&num_exist[1]&&num_exist[2]&&num_exist[3]){
return true;
}
return false;

}

}

3. 關於C語言的完全數的編程

完全數
正整數n的所有小於n的不同正因數之和若等於n本身,稱數n為完全數。
例如,6的正因數為1,2,3,而6=1=2+3,則6是一個完全數。
試求指定區域內的完全數。
1、演算法分析
對指定區域中的每一個數A實施窮舉判別。根據完全數的定義,為了判別正數A是不是完全數,用試商法找出A的所有小於A的因數K。顯然,1<=K<=A/2。注意到1是任何整數的因數,先把因數1確定下來,即因數和S賦初值1,然後設置K從2到A/2的循環,由表達式A/K判別K是否是A的因數,並求出A的因數累加和S。最後若滿足條件A=S說明A是完全數,作列印輸出。把n的因數從1開始,由小到大排列,寫成和式。
程序代碼如下:
#include
void main()
{
int a,s,k;
int n=0;
printf("(2,10000)中的完全數: ");
for(a=2;a<=10000;a++)
{
s=1;
for(k=2;k<=a/2;k++)
if((float)a/k==a/k) s=s+k;
if(s!=a)goto A;
n=n+1;
printf("%d:%d=1",n,a);
for(k=2;k<=a/2;k++)
if((float)a/k==a/k)printf("+ %d",k);
printf("\n");
A:;
}
}

4. 關於c++編程:如何做兩數之和

c++基本編程之兩個數的和,參考代碼如下:
<span style="font-size:18px;color:#3333ff;">#include <iostream>
using namespace std;
int main()
{
cout<<"Enter two number:"<<endl;
int v1,v2;
cin>>v1>>v2;
cout<<"The sum of"<<v1<<"and"<<v2<<"is"<<v1+v2<<endl;
return 0;

}</span>

熱點內容
原神電腦配置怎麼玩不卡 發布:2025-07-20 18:07:06 瀏覽:955
反編譯獲取原代碼 發布:2025-07-20 17:49:43 瀏覽:492
plc編譯怎麼找 發布:2025-07-20 17:48:56 瀏覽:162
無效的宏名稱將編譯啞宏 發布:2025-07-20 17:48:16 瀏覽:155
250萬解壓 發布:2025-07-20 17:44:52 瀏覽:620
騰訊視頻上傳廣告 發布:2025-07-20 17:35:55 瀏覽:406
掘地求升免費腳本 發布:2025-07-20 17:32:06 瀏覽:962
linux設置python環境變數 發布:2025-07-20 17:22:49 瀏覽:242
柱底層加密區 發布:2025-07-20 17:16:20 瀏覽:913
安卓ids是什麼文件 發布:2025-07-20 17:16:14 瀏覽:668