/*PROGRAM DERET*/
#pragma argsused
#include<conio.h>
#include<iostream.h>
#include<math.h>
int main()
{
int jum1, jum2, jum3,tot, n, i, a, b, fib, jum, muj, c;
cout<<"PROGRAM KLASIFIKASI BILANGAN"<<endl;
cout<<"----------------------------"<<endl;
cout<<"Masukkan banyaknya bilangan = "; cin>>n;
cout<<endl;
cout<<"Deret bilangan : ";
for (i=1; i<=n; i++)
{
cout<<i<<" ";
}
cout<<endl;
jum1=0;
cout<<"Bilangan habis dibagi 2 : ";
for (i=1; i<=n; i++)
{
if(i%2==0) {cout<<i<<" "; jum1=jum1+i;}
}
cout<<endl;
jum2=0;
cout<<"Bilangan habis dibagi 3 : ";
for (i=1; i<=n; i++)
{
if(i%3==0) {cout<<i<<" "; jum2=jum2+i;}
}
cout<<endl;
jum3=0;
cout<<"Bilangan habis dibagi 5 : ";
for (i=1; i<=n; i++)
{
if(i%5==0) {cout<<i<<" "; jum3=jum3+i;}
}
cout<<endl;
jum=0;
cout<<"Bilangan habis dibagi 7 : ";
for (i=1; i<=n; i++)
{
if(i%7==0) {cout<<i<<" "; jum=jum+i;}
}
cout<<endl;
muj=0;
cout<<"Bilangan habis dibagi 11 : ";
for (i=1; i<=n; i++)
{
if(i%11==0) {cout<<i<<" "; muj=muj+i;}
}
cout<<endl;
cout<<"Bilangan fibonaci : ";
c=1; b=1; fib=0;
for (i=1; i<=n; i++)
{
a=c;
c=b+c;
b=a;
if(b<=n) {cout<<b<<" "; fib=fib+b;}
}
cout<<endl;
cout<<endl;
cout<<endl;
tot=jum+jum1+jum2+jum3+muj+fib;
cout<<"Total habis dibagi 2 = "<<jum1<<endl;
cout<<"Total keluaran 3 = "<<jum2<<endl;
cout<<"Total keluaran 5 = "<<jum3<<endl;
cout<<"Total keluaran 7 = "<<jum<<endl;
cout<<"Total Keluaran 11 = "<<muj<<endl;
cout<<"Total bil fibonaci = "<<fib<<endl;
cout<<"-----------------------------"<<endl;
cout<<"Jumlah total bilangan = "<<tot<<endl;
cout<<"Rata-rata biloangan = "<<tot/6;
getch();
}
0 komentar:
Posting Komentar