Paano Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Maramihang Mga Wika

Paano Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Maramihang Mga Wika

Kapag naghahanap upang mapahusay ang iyong mga kasanayan sa pag-program, malamang na gugustuhin mong malaman ang tungkol sa mga pagkakasunud-sunod ng geometriko sa isang punto. Sa isang sunod-sunod na geometriko, ang bawat term ay matatagpuan sa pamamagitan ng pagpaparami ng nakaraang term sa pamamagitan ng isang pare-pareho.





Sa artikulong ito, malalaman mo kung paano makahanap ng kabuuan ng seryeng geometric gamit ang Python, C ++, JavaScript, at C.





Ano ang isang Geometric Series?

Ang kabuuan ng mga tuntunin ng isang walang hangganang pagkakasunud-sunod ng geometriko ay tinatawag na isang seryeng geometriko. Ang pagkakasunud-sunod ng geometriko o pag-unlad na geometriko ay tinukoy bilang mga sumusunod:





kung paano pribadong mensahe sa youtube app
a, ar, ar², ar³, ...

saan,

a = First term
r = Common ratio

Pahayag ng Suliranin

Nabigyan ka ng unang termino, karaniwang ratio, at hindi. ng mga termino ng seryeng geometric. Kailangan mong hanapin ang kabuuan ng seryeng geometric. Halimbawa : Hayaan munaTerm = 1, commonRatio = 2, at noOfTerms = 8. Serye ng Geometric: 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 Kabuuan ng mga seryeng heometriko: 255 Sa gayon, ang output ay 255.



Iterative Approach upang Mahanap ang Kabuuan ng isang Serye ng Geometric

Una, tingnan natin ang umuulit na paraan upang makahanap ng kabuuan ng isang seryeng geometric. Malalaman mo kung paano ito gawin sa bawat pangunahing wika ng programa sa ibaba.

C ++ Program upang Mahahanap ang Kabuuan ng isang Geometric Series Gamit ang Iteration

Nasa ibaba ang programa ng C ++ upang mahanap ang kabuuan ng isang seryeng geometric gamit ang pag-ulit:





// C++ program to find the sum of geometric series
#include
using namespace std;
// Function to find the sum of geometric series
float sumOfGeometricSeries(float firstTerm, float commonRatio, int noOfTerms)
{
float result = 0;
for (int i=0; i {
result = result + firstTerm;
firstTerm = firstTerm * commonRatio;
}
return result;
}
int main()
{
float firstTerm = 1;
float commonRatio = 2;
int noOfTerms = 8;
cout << 'First Term: ' << firstTerm << endl;
cout << 'Common Ratio: ' << commonRatio << endl;
cout << 'Number of Terms: ' << noOfTerms << endl;
cout << 'Sum of the geometric series: ' << sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms) << endl;
return 0;
}

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Python Program upang Mahahanap ang Kabuuan ng isang Geometric Series Gamit ang Iteration

Nasa ibaba ang programa ng Python upang mahanap ang kabuuan ng isang seryeng geometric gamit ang pag-ulit:





# Python program to find the sum of geometric series
# Function to find the sum of geometric series
def sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms):
result = 0
for i in range(noOfTerms):
result = result + firstTerm
firstTerm = firstTerm * commonRatio
return result
firstTerm = 1
commonRatio = 2
noOfTerms = 8
print('First Term:', firstTerm)
print('Common Ratio:', commonRatio)
print('Number of Terms:', noOfTerms)
print('Sum of the geometric series:', sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms))

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Kaugnay: Paano Mag-print ng 'Kumusta, Mundo!' sa Pinakatanyag na Mga Wika sa Programming

Program sa JavaScript upang Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Iteration

Nasa ibaba ang programa ng JavaScript upang mahanap ang kabuuan ng isang seryeng geometric gamit ang pag-ulit:

// JavaScript program to find the sum of geometric series
// Function to find the sum of geometric series
function sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms) {
var result = 0;
for (let i=0; i {
result = result + firstTerm;
firstTerm = firstTerm * commonRatio;
}
return result;
}

var firstTerm = 1;
var commonRatio = 2;
var noOfTerms = 8;
document.write('First Term: ' + firstTerm + '
');
document.write('Common Ratio: ' + commonRatio + '
');
document.write('Number of Terms: ' + noOfTerms + '
');
document.write('Sum of the geometric series: ' + sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms));

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

C Program upang Mahahanap ang Kabuuan ng isang Geometric Series Gamit ang Iteration

Nasa ibaba ang programa ng C upang mahanap ang kabuuan ng isang seryeng geometric gamit ang pag-ulit:

// C program to find the sum of geometric series
#include
// Function to find the sum of geometric series
float sumOfGeometricSeries(float firstTerm, float commonRatio, int noOfTerms)
{
float result = 0;
for (int i=0; i {
result = result + firstTerm;
firstTerm = firstTerm * commonRatio;
}
return result;
}
int main()
{
float firstTerm = 1;
float commonRatio = 2;
int noOfTerms = 8;
printf('First Term: %f ⁠n', firstTerm);
printf('Common Ratio: %f ⁠n', commonRatio);
printf('Number of Terms: %d ⁠n', noOfTerms);
printf('Sum of the geometric series: %f ⁠n', sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms));
return 0;
}

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Isang Mahusay na Diskarte upang Makita ang Kabuuan ng isang Serye ng Geometric Gamit ang Formula

Maaari mong gamitin ang sumusunod na pormula upang mahanap ang kabuuan ng seryeng geometric:

Sum of geometric series = a(1 – rn)/(1 – r)

saan,

a = First term
d = Common ratio
n = No. of terms

C ++ Program upang Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Formula

Nasa ibaba ang programa ng C ++ upang mahanap ang kabuuan ng isang seryeng geometric gamit ang formula:

// C++ program to find the sum of geometric series
#include
using namespace std;
// Function to find the sum of geometric series
float sumOfGeometricSeries(float firstTerm, float commonRatio, int noOfTerms)
{
return (firstTerm * (1 - pow(commonRatio, noOfTerms))) / (1 - commonRatio);
}
int main()
{
float firstTerm = 1;
float commonRatio = 2;
int noOfTerms = 8;
cout << 'First Term: ' << firstTerm << endl;
cout << 'Common Ratio: ' << commonRatio << endl;
cout << 'Number of Terms: ' << noOfTerms << endl;
cout << 'Sum of the geometric series: ' << sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms) << endl;
return 0;
}

Output:

kung paano gumawa ng mods para sa minecraft
First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Python Program upang Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Formula

Nasa ibaba ang programa ng Python upang mahanap ang kabuuan ng isang seryeng geometriko gamit ang formula:

# Python program to find the sum of geometric series
# Function to find the sum of geometric series
def sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms):
return (firstTerm * (1 - pow(commonRatio, noOfTerms))) / (1 - commonRatio)
firstTerm = 1
commonRatio = 2
noOfTerms = 8
print('First Term:', firstTerm)
print('Common Ratio:', commonRatio)
print('Number of Terms:', noOfTerms)
print('Sum of the geometric series:', sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms))

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Kaugnay: Paano Makahanap ng LCM at GCD ng Dalawang Bilang sa Maramihang Mga Wika

libreng maida-download na pelikula upang panoorin offline

Program sa JavaScript upang Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Formula

Nasa ibaba ang programa ng JavaScript upang mahanap ang kabuuan ng isang seryeng geometric gamit ang formula:

// JavaScript program to find the sum of geometric series
// Function to find the sum of geometric series
function sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms) {
return (firstTerm * (1 - Math.pow(commonRatio, noOfTerms))) / (1 - commonRatio);
}

var firstTerm = 1;
var commonRatio = 2;
var noOfTerms = 8;
document.write('First Term: ' + firstTerm + '
');
document.write('Common Ratio: ' + commonRatio + '
');
document.write('Number of Terms: ' + noOfTerms + '
');
document.write('Sum of the geometric series: ' + sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms));

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Kaugnay: Paano Bilangin ang Mga Nangyayari ng isang Naibigay na Character sa isang String

C Program upang Mahahanap ang Kabuuan ng isang Serye ng Geometric Gamit ang Formula

Nasa ibaba ang programa ng C upang makahanap ng kabuuan ng isang seryeng geometric gamit ang pormula:

// C program to find the sum of geometric series
#include
#include
// Function to find the sum of geometric series
float sumOfGeometricSeries(float firstTerm, float commonRatio, int noOfTerms)
{
return (firstTerm * (1 - pow(commonRatio, noOfTerms))) / (1 - commonRatio);
}
int main()
{
float firstTerm = 1;
float commonRatio = 2;
int noOfTerms = 8;
printf('First Term: %f ⁠n', firstTerm);
printf('Common Ratio: %f ⁠n', commonRatio);
printf('Number of Terms: %d ⁠n', noOfTerms);
printf('Sum of the geometric series: %f ⁠n', sumOfGeometricSeries(firstTerm, commonRatio, noOfTerms));
return 0;
}

Output:

First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Ngayon Alam Mo Kung Paano Makahanap ng Mga Saklaw ng Serye ng Geometric Gamit ang Iba't ibang Mga Wika sa Programming

Sa artikulong ito, natutunan mo kung paano makahanap ng kabuuan ng seryeng geometric gamit ang dalawang diskarte: pag-ulit at pormula. Natutunan mo rin kung paano malutas ang problemang ito gamit ang iba't ibang mga wika sa pagprograma tulad ng Python, C ++, JavaScript, at C.

Ang Python ay isang wikang pangkalahatang layunin sa pagprograma na may pagtuon sa kakayahang mabasa ang code. Maaari mong gamitin ang Python para sa agham ng data, pag-aaral ng makina, pagbuo ng web, pagproseso ng imahe, paningin sa computer, atbp. Ito ay isa sa mga pinaka maraming nalalaman na mga wika sa pagprograma. Napakahalaga nitong tuklasin ang malakas na wikang ito sa pagprograma.

Magbahagi Magbahagi Mag-tweet Email 3 Mga Paraan upang Suriin kung Ang isang Email Ay Totoo o Pekeng

Kung nakatanggap ka ng isang email na mukhang medyo nagdududa, palaging pinakamahusay na suriin ang pagiging tunay nito. Narito ang tatlong paraan upang malaman kung ang isang email ay totoo.

Basahin Susunod
Mga Kaugnay na Paksa
  • Programming
  • Sawa
  • JavaScript
  • C Programming
  • Programming
Tungkol sa May-akda Yuvraj Chandra(60 Mga Artikulo Na-publish)

Si Yuvraj ay isang undergraduate na mag-aaral sa Computer Science sa University of Delhi, India. Masigasig siya sa Full Stack Web Development. Kapag hindi siya nagsusulat, sinisiyasat niya ang lalim ng iba't ibang mga teknolohiya.

Higit pa Mula kay Yuvraj Chandra

Mag-subscribe sa aming newsletter

Sumali sa aming newsletter para sa mga tip sa tech, pagsusuri, libreng ebook, at eksklusibong deal!

Mag-click dito upang mag-subscribe