C言語でforループを使用して、指定された数字の積を見つける方法は?
ユーザーは数値を入力し、指定された数値を個々の数字に分割し、最後にforループを使用してそれらの個々の数字の積を見つける必要があります。
指定された数字の積を見つけるロジック 次のとおりです-
for(product = 1; num > 0; num = num / 10){
rem = num % 10;
product = product * rem;
} 例1
以下は、forループを使用して特定の数値の桁の積を見つけるCプログラムです-
#include <stdio.h>
int main(){
int num, rem, product;
printf("enter the number : ");
scanf("%d", & num);
for(product = 1; num > 0; num = num / 10){
rem = num % 10;
product = product * rem;
}
printf(" result = %d", product);
return 0;
} 出力
上記のプログラムを実行すると、次の結果が得られます-
enter the number: 269 result = 108 enter the number: 12345 result = 120
例2
whileループを使用して、指定された数値の桁の積を見つける別の例を考えてみましょう。
#include <stdio.h>
int main(){
int num, rem, product=1;
printf("enter the number : ");
scanf("%d", & num);
while(num != 0){
rem = num % 10;
product = product * rem;
num = num /10;
}
printf(" result = %d", product);
return 0;
} 出力
上記のプログラムを実行すると、次の結果が得られます-
enter the number: 257 result = 70 enter the number: 89 result = 72
-
Pythonを使用して特定の数値の桁数を見つける方法は?
このプログラムでは、ユーザーが指定した整数の桁数を見つける必要があります。 例 ユーザー入力:123、出力:3 ユーザー入力:1987、出力:4 アルゴリズム Step 1: Take Integer value as input value from the userStep 2: Divide the number by 10 and convert the quotient into Integer typeStep 3: If quotient is not 0, update count of digit by 1Step 4: If quotient is 0, stop
-
Windows 10 または Windows 11 のプロダクト キーを見つける方法
25 文字のコードである Windows のプロダクト キー (ソフトウェア キーとも呼ばれます) は、オペレーティング システムの認証に必要な確認コードです。プロダクト キーを使用すると、基本的に使用中の製品がオリジナルであることを保証できます。プロダクト キーを見つける必要がある場合でも、心配はいりません。以下では、Windows プロダクト キーを見つけるさまざまな方法について説明します。早速始めましょう。 1.メールをチェック ほとんどの場合、メールの受信トレイで Windows 10 または Windows 11 のプロダクト キーを見つけることができるはずです。受信トレイでは、W