求出数组中元素的总和_数组中所有元素的总和可被给定数K整除
生活随笔
收集整理的這篇文章主要介紹了
求出数组中元素的总和_数组中所有元素的总和可被给定数K整除
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
求出數組中元素的總和
This program will help to find out the sum of elements in an array which is divisible by a number K. It uses the basic concept of modulo '%' or the remainder of a number.
該程序將幫助找出數組中被數字K整除的元素之和 。 它使用“%”模或數字余數的基本概念。
Program:
程序:
#include<iostream>using namespace std;int main(){int n, ele;cout<<"Enter the size of the array.\n";cin>>n;int A[n];cout<<"Enter elements in the array\n";for(int i =0;i<n;i++){cin>>A[i];}cout<<"Enter the element to be divisible by.\n";cin>>ele;int sum = 0;for(int i =0;i<n;i++){if(A[i]%ele==0){sum += A[i];}}cout<<"The sum is "<<sum<<endl;return 0; }Output
輸出量
Enter the size of the array. 6 Enter elements in the array 2 3 4 5 6 7 Enter the element to be divisible by. 3 The sum is 9翻譯自: https://www.includehelp.com/cpp-programs/sum-of-all-the-elements-in-an-array-divisible-by-a-given-number-k.aspx
求出數組中元素的總和
總結
以上是生活随笔為你收集整理的求出数组中元素的总和_数组中所有元素的总和可被给定数K整除的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iis php mysql 集成_如何在
- 下一篇: Java ObjectInputStre