Birden Fazla Dil Kullanan Geometrik Serilerin Toplamı Nasıl Bulunur?

Birden Fazla Dil Kullanan Geometrik Serilerin Toplamı Nasıl Bulunur?

Programlama becerilerinizi geliştirmek istediğinizde, muhtemelen bir noktada geometrik diziler hakkında bilgi edinmek isteyeceksiniz. Geometrik bir dizide, her terim bir önceki terimin bir sabitle çarpılmasıyla bulunur.





Bu makalede Python, C++, JavaScript ve C kullanarak geometrik serilerin toplamını nasıl bulacağınızı öğreneceksiniz.





Geometrik Seri Nedir?

Sonsuz bir geometrik dizinin terimlerinin toplamına geometrik dizi denir. Geometrik dizi veya geometrik ilerleme aşağıdaki gibi gösterilir:





xbox one denetleyicisi nasıl sökülür
a, ar, ar², ar³, ...

nerede,

a = First term
r = Common ratio

Sorun bildirimi

Size ilk terim, ortak oran verildi ve hayır. geometrik serinin terimleri. Geometrik serinin toplamını bulmanız gerekiyor. Örnek : firstTerm = 1, commonRatio = 2 ve noOfTerms = 8. Geometrik Seriler: 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 Geometrik serilerin toplamı: 255 Böylece çıktı 255'tir.



Geometrik Serilerin Toplamını Bulmak İçin Yinelemeli Yaklaşım

İlk olarak, bir geometrik serinin toplamını bulmanın yinelemeli yoluna bir göz atalım. Aşağıda her bir ana programlama diliyle bunu nasıl yapacağınızı öğreneceksiniz.

Yineleme Kullanarak Geometrik Serilerin Toplamını Bulan C++ Programı

Aşağıda yineleme kullanarak bir geometrik serinin toplamını bulan C++ programı verilmiştir:





// 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;
}

Çıktı:

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

Yineleme Kullanarak Geometrik Serilerin Toplamını Bulan Python Programı

Aşağıda yineleme kullanarak bir geometrik serinin toplamını bulan Python programı verilmiştir:





# 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))

Çıktı:

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

İlgili: 'Merhaba Dünya!' Nasıl Yazdırılır? En Popüler Programlama Dillerinde

Yineleme Kullanarak Geometrik Serilerin Toplamını Bulan JavaScript Programı

Aşağıda yineleme kullanarak bir geometrik serinin toplamını bulan JavaScript programı verilmiştir:

// 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));

Çıktı:

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

Yineleme Kullanarak Geometrik Serilerin Toplamını Bulan C Programı

Aşağıda yineleme kullanarak bir geometrik serinin toplamını bulan C programı verilmiştir:

// 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;
}

Çıktı:

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

Formül Kullanarak Geometrik Serilerin Toplamını Bulmak İçin Etkili Bir Yaklaşım

Geometrik serilerin toplamını bulmak için aşağıdaki formülü kullanabilirsiniz:

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

nerede,

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

Formül Kullanarak Geometrik Serilerin Toplamını Bulan C++ Programı

Aşağıdaki formülü kullanarak bir geometrik serinin toplamını bulan C++ programı:

// 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;
}

Çıktı:

microsoft office satın almak için en ucuz yer
First Term: 1
Common Ratio: 2
Number of Terms: 8
Sum of the geometric series: 255

Formül Kullanarak Geometrik Serilerin Toplamını Bulan Python Programı

Aşağıda formülü kullanarak bir geometrik serinin toplamını bulan Python programı verilmiştir:

# 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))

Çıktı:

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

İlgili: Birden Çok Dilde İki Sayının LCM ve GCD'si Nasıl Bulunur?

dünyanın en popüler uygulaması nedir

Formül Kullanarak Geometrik Serilerin Toplamını Bulan JavaScript Programı

Aşağıda, formülü kullanarak bir geometrik serinin toplamını bulan JavaScript programı verilmiştir:

// 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));

Çıktı:

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

İlgili: Bir Dizede Verilen Bir Karakterin Oluşumları Nasıl Sayılır

Bir Geometrik Serinin Toplamını Formül Kullanarak Bulan C Programı

Aşağıdaki formülü kullanarak bir geometrik serinin toplamını bulan C programı:

// 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;
}

Çıktı:

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

Artık Farklı Programlama Dillerini Kullanarak Geometrik Seri Toplamlarını Nasıl Bulacağınızı Biliyorsunuz

Bu makalede, iki yaklaşımı kullanarak geometrik serilerin toplamını nasıl bulacağınızı öğrendiniz: yineleme ve formül. Python, C++, JavaScript ve C gibi çeşitli programlama dillerini kullanarak bu sorunu nasıl çözeceğinizi de öğrendiniz.

Python, kod okunabilirliğine odaklanan genel amaçlı bir programlama dilidir. Python'u veri bilimi, makine öğrenimi, web geliştirme, görüntü işleme, bilgisayarla görme vb. için kullanabilirsiniz. En çok yönlü programlama dillerinden biridir. Bu güçlü programlama dilini keşfetmeye çok değer.

Paylaş Paylaş Cıvıldamak E-posta Bir E-postanın Gerçek mi Sahte mi Olduğunu Kontrol Etmenin 3 Yolu

Biraz şüpheli görünen bir e-posta aldıysanız, orijinalliğini kontrol etmek her zaman en iyisidir. İşte bir e-postanın gerçek olup olmadığını anlamanın üç yolu.

Sonrakini Oku
İlgili konular
  • Programlama
  • piton
  • JavaScript
  • C Programlama
  • Programlama
Yazar hakkında Yuvraj Chandra(60 Makale Yayımlandı)

Yuvraj, Hindistan Delhi Üniversitesi'nde Bilgisayar Bilimleri lisans öğrencisidir. Full Stack Web Geliştirme konusunda tutkulu. Yazmadığı zamanlarda farklı teknolojilerin derinliğini keşfediyor.

Yuvraj Chandra'dan Daha Fazla

Haber bültenimize abone ol

Teknik ipuçları, incelemeler, ücretsiz e-kitaplar ve özel fırsatlar için bültenimize katılın!

Abone olmak için buraya tıklayın