38.找出100-999之間各位相加等於15的數及個數
給定程式中,函式fun的功能是:找出100至x(x<999)之間各位上的數字之和為15的所有整數,然後輸出,符合條件的整數個數作為函式返回值。
#include<stdio.h> fun(int x) { int n, s1, s2, s3, t; n = 0; t = 100; while (t <= x) { s1 = t % 10; s2 = (t / 10) % 10; s3 = t / 100; if ((s1 + s2 + s3) == 15) { printf(" %d ", t); n++; } t++; } return n; } int main() { int x = -1; while (x > 999 || x < 0) { printf("Please input (0<x<99):"); scanf_s("%d", &x); printf("\nThe result is:%d\n", fun(x)); getchar(); getchar(); return 0; } }
相關推薦
38.找出100-999之間各位相加等於15的數及個數
給定程式中,函式fun的功能是:找出100至x(x<999)之間各位上的數字之和為15的所有整數,然後輸出,符合條件的整數個數作為函式返回值。 #include<stdio.h> fun(int x) { int n, s1, s2, s3, t;
Python練習題5(求水仙花數):編寫一個程式,求 100~999 之間的所有水仙花數 (如果一個 3 位數等於其各位數字的立方和,則稱這個數為水仙花數)
方法一:使用int和str,將int轉成字串拼接後再轉成int。 1 for i in range(1,10): 2 for j in range(0,10): 3 for k in range(0,10): 4 num = int(str(i) + s
c/c++_找出100到200之間的全部素數並輸出
/* * Copyright (c) 2011, 煙臺大學計算機學院 * All rights reserved. * 作 者:解曉東 * 完成日期:2012 年 10 月 2
python基本語法2.8--找出100以內的素數
string color utf-8 blog ring div prim style odi 問題描述:找出某一範圍內的素數 思路:給每個數字作標註 首先,要循環遍歷到該範圍內的所有數,一個大循環 然後,遍歷2到n-1。看是否能被整除 代碼: # -*-
java筆試題:找出3~999的水仙花數的三種實現方式
style col 展示 ava num get 實現 sys pack 第一種方式: package test; public class Exsercise { public static void main(String[] args) {
找出陣列中相加等於某數的兩個數
public static void main(String[] args) throws IOException { int[] a={4,5,3,2,7,9,1}; findS
Python-三種方法求100-999之間的水仙花數
題目:算出100-999之間的水仙花數 水仙花數是指百位的3次方 + 十位的3次方 + 個位的三次方等於原數的整數 方法一:將數字轉換為字串,用索引獲取百位十位個位數字 for i in range(100,1000): s=str(i) if int(s[0])*
c語言 求出0-999之間的水仙花數並輸出
求出0~999之間的所有“水仙花數”並輸出。 “水仙花數”是指一個三位數,其各位數字的立方和確好等於該數本身,如;153=1+5+3?,則153是一個“水仙花數”。 /* 在數論中,水仙花數(Narcissistic number)也稱為自戀數、自冪數、阿姆斯壯
C語言 1. switch語句的使用2.輸出菱形3..求出0~999之間的所有”水仙花數“,並輸出
浮點型和零相比? #define EXP 0.000000……1 在不同作業系統下程式碼結果可能不一樣,所以定義一個精度 switch語句的使用: int main() { int day=0; scanf("%d",&day); switch(d
【C語言】輸出100~999之間的所有“水仙花數”
“水仙花數”: “水仙花數”又稱為“阿姆斯特朗數”。如果一個n(n≥3)位數的各位數字的n次冪之和等於該數本身,則該數稱為“水仙花數”。如:153=1³+5³+3³。 問題:輸出100~999之間的所有“水仙花數”。 實現思路: 根據
寫出一個小程式,求出100-200之間的質數的個數並輸出這些數
質數就是素數,是除了1和它本身以外不再有其他因數的數稱為質數。 如果知道迴圈的次數就用for迴圈,如果不知道迴圈的次數的話就用while迴圈. 分析: 1.100-200之間的數,肯定需要用到迴圈
C++程式設計小練習(一) 找出100以內的素數
int i,j,n,a[101]; //對陣列賦值 for (i=1;i<=100;i++) a[i]=i; a[1]=0; //將非素數賦值為0。 for (i=2;i<sqrt(100);i++) for (j=i+1;j<
編寫一個找出100以內質數的程式
質數即除了1和本身而沒有別的約數;而合數剛好與質數相反。 用javascript寫出找出100以內質數的程式如下: 用瀏覽器執行後開啟,可以在控制檯看到執行結果如下: 當然,如果我們想找100以內的合數只需要把上面最後一個if語句中的flay==0改為flag==1即可,
找出100——200間的全部素數
/* 煙臺大學計算機學院 作者:任子儀 日期:213年12月14日 問題描述: 樣例輸入: 樣例輸出: 問題分析: */ #include <iostream> #include <iomanip> #include &l
leetcode 1: 找出兩個數相加等於給定數 two sum
問題描述 對於一個給定的陣列,找出2個數,它們滿足2個數的和等於一個特定的數,返回這兩個數的索引。(從1開始) Given an array of integers, find two numbers such that they add up to a s
打印出101~999之間的所有水仙花數
數字i=a^3+b^3+c^3 個位數:c=i%10; 百位數:a=parseIn(i/100); 十位數:b=(i-(a*100-c))/10; 分別獲得個位十位百位之後i == a^3+b^3+c^3;符合則為水仙花 //100-999之間的水仙花數 //水仙花
python練習2 計算100-999之間的水仙花數
如果一個 3 位數等於其各位數字的立方和,則稱這個數為水仙花數。例如:153 = 1^3 + 5^3 + 3^3,因此 153 就是一個水仙花數,求100~999之間的水仙花數 我的答案1 #!/u
C語言小程式:找出100以內素數
C語言 #include<stdio.h> int main() { int i = 0;int j = 0;int t = 1;for(i = 2;i <= 100;i++){f
Java面試寶典——求陣列中兩兩相加等於指定數的組合種數 + 如何找出陣列中第k個最小的數
求陣列中兩兩相加等於指定數的組合種數package demos.array; import java.util.Arrays; /** * @author wyl * @time 2018年7
小王對既是素數又是迴文的數特別感興趣。比如說151既是素數又是個迴文。現在小王想要你幫助他找出某個範圍內的素數迴文數,請你寫個程式找出 a 跟b 之間滿足條件的數。(5
#include <iostream> #include <cstdio> using namespace std; const int N=10000001; bool prime[N]; int count=0; int primehuiwen[