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.mzph.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是后…