輸入一個n,輸出2到n的詳細素數值
#include<algorithm>
#include<cmath>
int judge(int a)
{
int j;
for (j = 2; j <= sqrt(a); j++)
{
if (a%j == 0)
return 1;
}
return 0;
}
int main()
{
int i;
for (i = 1; i < 100; i++)
{
if (judge(i) == 0)
printf("%d", i);
return 0;
}
輸入一個n,輸出2到n的詳細素數值
相關推薦
輸入一個n,輸出2到n的詳細素數值
ace pan include class printf pos hit == article #include<stdio.h> #include<algorithm> #include<cmath> int ju
解決:輸入一個n輸出以n為長度的二進位制數串的所有可能,並從小到大輸出所有
一開始看到這個問題時,會想到用0和1的排序,去尋找其中的規律,總結出表示式。 看似可行,但是在尋找規律時會發現每種情況之間都有一定的規律但不好用表示式表示出來,如: n=3; 輸出結果為: 000;. 001;. 010;. 011;. 100;. 101;.
ACMNO.14一球從M米高度自由下落,每次落地後返回原高度的一半,再落下。 它在第N次落地時反彈多高?共經過多少米? 保留兩位小數 輸入 M N 輸出 它在第N次落地時反彈多高?共經過多少米
題目描述 一球從M米高度自由下落,每次落地後返回原高度的一半,再落下。 它在第N次落地時反彈多高?共經過多少米? 保留兩位小數 輸入 M N 輸出 它在第N次落地時反彈多高?共經過多少米? 保留兩位小數,空格隔開,放在一行 樣例輸入 1000 5
java小程式:輸入五個整數順序輸出,再輸入一個順序輸出
//任意輸入5個整數,從小到大的順序輸出 import java.util.Scanner; public class Kaohe1 {public static void main(String[] args) {// TODO Auto-generated method
輸入一個n,然後在螢幕上打印出NxN 的矩陣!
/* Function: printCube Description: generate the Cube in array and print it Input: [arr
求階乘,輸入一個正整數 n,輸出n!
factor i++ print 階乘 pri tor n) printf main #include<stdio.h>int factorial (int n); int main(){ int n; scanf("%d",&n); printf("
字符串數組 輸入3個字符串,要求按由小到大的字母順序輸出; 輸入n個學生的姓名和學號到字符串數組中,在輸入一個姓名,如果班級有該生則返回其信息,否則返回本班無此人
emp zhang 查詢 i+1 [1] 返回 思路 lan 字符數組 輸入3個字符串,要求按由小到大的字母順序輸出 如 輸入franch england china,輸出結果是china england franch 三個數排序輸出,比較三個數的大小怎麽做? a=18 b
輸入一個正整數n,輸出所有和為n的連續正整數序列
1 public static void main(String[] args) { 2 Scanner sc = new Scanner(System.in); 3 while (true) { 4 System.out.prin
大家都知道斐波那契數列,現在要求輸入一個整數n,請你輸出斐波那契數列的第n項(從0開始,第0項為0)。
題目描述 大家都知道斐波那契數列,現在要求輸入一個整數n,請你輸出斐波那契數列的第n項(從0開始,第0項為0)。 n<=39 /* 思路: 就是簡單的斐波那契數列,按照正常的思路求解即可 可以分為遞迴和非遞迴,這裡介紹非遞迴的方式 */ class Solution { pub
ACMNO.9求Sn=a+aa+aaa+…+aa…aaa(有n個a)之值,其中a是一個數字。 例如:2+22+222+2222+22222(n=5),n由鍵盤輸入。 輸入 n 輸出 a=2 時
題目描述 求Sn=a+aa+aaa+…+aa…aaa(有n個a)之值,其中a是一個數字。 例如:2+22+222+2222+22222(n=5),n由鍵盤輸入。 輸入 n 輸出 a=2 時的Sn 樣例輸入 5 樣例輸出 24690 來源/
ACMNO.13求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一個數字。 輸入 n 輸出 和 樣例輸入 5 樣例輸出 153
題目描述 求Sn=1!+2!+3!+4!+5!+…+n!之值,其中n是一個數字。 輸入 n 輸出 和 樣例輸入 5 樣例輸出 153 來源/分類 C語言 題目截圖: 思路: 首先要想到使用兩個for迴圈語句,進行巢狀迴圈!
輸入一個正整數n,輸出n!的值。 其中n!=1*2*3*…*n。
問題描述 輸入一個正整數n,輸出n!的值。 其中n!=1*2*3*…*n。 演算法描述 n!可能很大,而計算機能表示的整數範圍有限,需要使用高精度計算的方法。使用一個數組A來表示一個大整數a,A[0]表示a的個位,A[1]表示a的十位,依次類推。 將a乘以一個整
輸入一個數字n輸出n以內的素數
思路:一個素數只能被1和本身相除,for迴圈從2開始到sqrt(這個數),一種是除到這個數/2 一種是 開根號 百度了之後大神給的答案:因為如果一個數不是素數是合數, 那麼一定可以由兩個自然數相乘得到, 其中一個大於或等於它的平方根,一個小於或等於它的平方根。並且成對出現
輸入一個正數n,輸出所有和為n的連續正數序列。
public class b { public static void main(String[] args) { getlx(15); } private static void getlx(int n) { //定義最小序列 int min = 1;
輸入一個正整數n,輸出1到n的所有排列
思路:字典序演算法 1、從序列的末端開始,找到第一個相鄰數組合,其中第一個數小於第二個數,比如:1 2 3 4,第一個組合是34,記錄3的位置為i; 2、從i位置之後的元素中,從末端開始找第一個大於它的數,就是4,交換這兩個數,變為 1 2 4 3; 3、將i位置之後的數全
N的階乘:輸入一個正整數N,輸出N的階乘
輸入描述: 正整數N(0<=N<=1000) 輸出描述: 輸入可能包括多組資料,對於每一組輸入資料,輸出N的階乘 輸入例子: 4 5 15 輸出例子: 24 120 13076743680
java實現輸入一個正整數n,輸出全部連續正整數相加後等於n的所有序列。
題目如下: 請用java實現輸入一個正整數n,輸出以下格式,全部連續正整數相加後等於n的所有序列。 例如: 15=1+2+3+4+5; 15=4+5+6; 15=7+8; 我從網上文章中得到的思路,
輸入一個int型整數,將其逆序輸出,每個數字後有一個空格。 將n按其逆序輸出,每個數字後有一個空格,輸出佔一行。例如,輸入12354,輸出4 5 3 2 1
#include<stdio.h>#include<math.h> int main(){ int n,a; scanf("%d",&n); while(1) { if(n>=10) { a=n%10; n=n/10; print
(用python來繪製一個空心菱形) 輸入一個整數n,輸出一個空心菱形,其中每個邊由n個'*'組成。
def kongxin(n): for i in range(n): print() for j in range(n - i - 1): print(' ', end='') for k in range(2 * i + 1): if k==0
c++,輸入一個整數值並輸出此整數的各數字反序的數值
#include<iostream> using namespace std; void func(int); int main() { int num; cout << "輸入一個整數:"; cin >> num; func(nu