whilekom.cpp

Bookmark and Share


#include<iostream.h>



main ()

{

float a,b,h;

int n;

cout<<"Deret Aritmatika\n";

cout<<"Masukkan Suku Pertama : ";cin>>a;

cout<<"Masukkan Bedanya : ";cin>>b;

cout<<"Masukkan Banyak Suku : ";cin>>n;

while (n<=0)

{

cout<<"Maaf, untuk banyak suku, Masukkan Angka Positif!!! ";

cin>>n;

}

if(b>0)

{for (h=a;h<=a+(n-1)*b;h+=b)

cout<<h<<" + ";

cout<<"\nSn= "<<0.5*n*(2*a+(n-1)*b);}

else if (b<0)

{for (h=a;h>=a+(n-1)*b;h+=b)

cout<<h<<" + ";

cout<<"\nSn= "<<0.5*n*(2*a+(n-1)*b);}

else

cout<<"...Bukan Deret Aritmatika...";

return 0;

}

{ 0 komentar... Views All / Send Comment! }

Posting Komentar

Powered By Blogger