c語言for循環++_C ++程序使用循環查找數字的冪

c語言for循環++

Here, we are going to calculate the value of Nth power of a number without using pow function.

在這里,我們將不使用pow函數計算數字的N 冪的值

The idea is using loop. We will be multiplying a number (initially with value 1) by the number input by user (of which we have to find the value of Nth power) for N times. For multiplying it by N times, we need to run our loop N times. Since we know the number of times loop will execute, so we are using for loop.

這個想法是使用循環。 我們將通過輸入的號碼被用戶乘以一個數字(初始值為1)(其中我們必須找到的 N功率值)為N次 。 為了將其乘以N倍,我們需要運行循環N次。 由于我們知道循環執行的次數,因此我們使用for循環。

Example:

例:

    Input:
base: 5, power: 4
Output:
625

C ++代碼使用循環查找數字的冪 (C++ code to find power of a number using loop)

#include <iostream>
using namespace std;
int main()
{
int num;
int a = 1;
int pw;
cout << "Enter a number: ";
cin >> num;
cout << "\n";
cout << "Enter a power : ";
cin >> pw;
cout << "\n";
for (int i = 1; i <= pw; i++) {
a = a * num;
}
cout << a;
return 0;
}

Output

輸出量

Enter a number: 5
Enter a power : 4
625

翻譯自: https://www.includehelp.com/cpp-programs/find-the-power-of-a-number-using-loop.aspx

c語言for循環++

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542084.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542084.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542084.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

廈門one_理想ONE真是“500萬內最好的車”?

提起羅永浩&#xff0c;不少人還停留在“砸冰箱、造手機”等早期事件。隨著網絡直播的興起&#xff0c;羅永浩轉戰直播帶貨行業&#xff0c;但老羅畢竟是老羅&#xff0c;雷人語錄一點沒比以前少。前一段時間&#xff0c;羅永浩在微博中稱&#xff1a;“理想ONE是你能在這個價位…

Data Collection

眾所周知&#xff0c;計算機領域論文是要以實驗為基礎的&#xff0c;而實驗的原料就是數據。不管是在圖像&#xff0c;文字或者語音領域&#xff0c;開源的數據都十分寶貴和重要。這里主要收集各領域的一些常用的公開數據集。 計算機視覺&#xff1a; 【ImageNet】 【Caltech P…

python—os模塊、時間模塊

os模塊 作用&#xff1a;os模塊是python標準庫中的一個用于訪問操作系統功能的模塊&#xff0c; os模塊提供了其他操作系統接口&#xff0c;可以實現跨平臺訪問。 使用&#xff1a; 1 . 返回操作系統類型 &#xff1a;os.name 值為&#xff1a;posix 是linux操作系統 值為&…

kotlin鍵值對數組_Kotlin程序檢查數組是否包含給定值

kotlin鍵值對數組Given an array and an element, we have to check whether array contains the given element or not. 給定一個數組和一個元素&#xff0c;我們必須檢查數組是否包含給定的元素。 Example: 例&#xff1a; Input:arr [34, 56, 7, 8, 21, 0, -6]element to…

enter sleep mode黑屏怎么解決_【linux】 不要再暴力關機了,講講我最近遇到的問題和完美解決方案...

歡迎關注我的個人公眾號&#xff1a;AI蝸牛車前言結束了每天的緊張的工作&#xff0c;這兩天真的有些肝。這兩天打打字&#xff0c;突然感覺手指頭疼起來了&#xff0c;想意識到成天打了十多個小時的鍵盤&#xff0c; 手指頭都疲勞了 之后這兩天基本上除了基本的吃睡&#xff…

重復T次的LIS的dp Codeforces Round #323 (Div. 2) D

http://codeforces.com/contest/583/problem/D 原題&#xff1a;You are given an array of positive integers a1,?a2,?...,?an??T of length n??T. We know that for any i?>?n it is true that ai??ai?-?n. Find the length of the longest non-decreasing …

微擎pc 導入前綴_段覆蓋前綴| 8086微處理器

微擎pc 導入前綴As we already know that the effective address is calculated by appending the segment registers value and adding up the value of the respective offset. But what if we want to choose some other offset than the assigned one. 眾所周知&#xff0…

python—面向對象

面向過程 面向對象&#xff1a; 面向過程&#xff1a;—側重于怎么做&#xff1f; 1.把完成某一個需求的 所有步驟 從頭到尾 逐步實現 2.根據開發要求&#xff0c;將某些功能獨立的代碼封裝成一個又一個函數 3.最后完成的代碼&#xff0c;就是順序的調用不同的函數 特點&#…

5中bug vue_蘋果官網出BUG!這些都只要一兩百元

近日&#xff0c;有網友在網上反饋稱&#xff0c;他發現蘋果官網商城出現了BUG&#xff01;眾多上千元的產品&#xff0c;BUG價只需一兩百元。比如Shure MOTIV MV88 Digital立體聲電容式麥克風配件。正常售價1288元&#xff0c;而BUG后的價格是235元。UBTECH Jimu Astrobot Cos…

常用壓縮,解壓與打包

常用壓縮格式&#xff1a; .zip .zg .bz2 .tar.gz .tar.bz2.zip格式壓縮zip 壓縮文件名 源文件#壓縮文件注&#xff1a;壓縮文件名寫.zip后綴是為了標記該文件的壓縮類型&#xff0c;方便管理。注&#xff1a;在壓縮時有壓縮格式轉換&#xff0c;所以當源文件很小時&#xff0c…

css禁用選中文本_使用CSS禁用文本選擇突出顯示

css禁用選中文本Introduction: 介紹&#xff1a; Texts are the most fundamental elements of any websites or web pages, they form the basis of the web pages or websites because if you don’t write something that you will not be able to present anything. There…

CDN加速實現—varnish

CDN介紹&#xff1a; 1 . 對cdn的理解&#xff1a; CDN的全稱是&#xff08;Content Delivery Network&#xff09;&#xff0c;即內容分發網絡&#xff1b;加速器&#xff0c;反向代理緩存。CDN系統能夠實時的根據網絡流量和各節點的連接&#xff0c;負載狀況以及到用戶的舉例…

3dmax如何拆分模型_3dmax制作裝飾柜1

大家好&#xff0c;今天我來為大家講解一下如何利用3dmax制作裝飾柜。我們需要制作裝飾柜模型&#xff0c;當我們為它添加一個材質后&#xff0c;它就是這樣的效果。單擊創建&#xff0c;選擇圖形&#xff0c;對象為樣條線&#xff0c;選擇矩形在場景中進行創建。單擊修改&…

TODO:macOS上ThinkPHP5和Semantic-UI集成

TODO&#xff1a;macOS上ThinkPHP5和Semantic-UI集成1. 全局安裝 (on OSX via homebrew)Composer 是 homebrew-php 項目的一部分2. 把Xcode升級到8.1后繼續安裝Composer3. 使用composer創建TP5項目MWL-Dispatchcomposer create-project topthink/think MWL-Dispatch4. 配置apac…

np.expm1_JavaScript中帶有示例的Math.expm1()方法

np.expm1JavaScript | Math.expm1()方法 (JavaScript | Math.expm1() Method) Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.expm1() method, we will learn about the expm1() method and its workin…

距離傳感器控制燈泡代碼_生迪全彩智能 LED 燈泡體驗評測

市面上大多數智能燈具無外乎智能控制&#xff0c;冷暖標準區間的簡單調光&#xff0c;僅僅滿足我們日常照明之外&#xff0c;似乎用處不多。如果有一款能在自己房間制造多彩氛圍的燈泡就好了。這次有幸體驗到了華為智能家居生態鏈產品生迪全彩智能 LED 燈泡&#xff0c;才發現彩…

mysql啟動與關閉(手動與自動)

手動管理mysql的啟動與關閉 [rootmysql ~]# service mysql start --手動啟動mysqlStarting MySQL. SUCCESS![rootmysql ~]# service mysql stop --手動關閉mysql Shutting down MySQL.. SUCCESS! [rootmysql ~]# mysqld --verbose --help --查看MySQL的默認參數的具體值 如果每…

JavaScript中帶有示例的Math.round()方法

JavaScript | Math.round()方法 (JavaScript | Math.round() Method) Math.round() is a function in math library of JavaScript that is used to round the given number floating-point number to the nearest integer value. Math.round()是JavaScript數學庫中的函數&…

內部導線拉力測試_珠海后環回收試驗機現金支付拉力試驗機回收和諧溫馨的環境...

珠海后環回收試驗機現金支付拉力試驗機回收和諧溫馨的環境深圳富興二手設備回收&#xff0c;拉力試驗機回收&#xff0c;恒溫恒濕箱回收&#xff0c;恒溫恒濕試驗箱回收&#xff0c;恒溫恒濕培養箱回收&#xff0c;高低溫試驗箱回收&#xff0c;高低溫沖擊試驗機回收&#xff0…

lvs負載均衡—ldirectord(DR模式的健康檢查)

作用&#xff1a; 健康檢查對企業而言也是由為重要&#xff0c;在生活中&#xff0c;有時候訪問網頁訪問不到&#xff0c;就會跳出來一些圖形告訴你訪問失敗&#xff0c;這就是健康檢查的作用&#xff0c;當服務器都掛掉的時候&#xff0c;告訴你暫時訪問不了。 ldirectord是后…