/*PROGRAM DERET BILANGAN MENGGUNAKAN FOR*/#pragma argused#include<conio.h>#include<iostream.h>#include<iomanip.h>
int main(){int jumgen,jumgan,i,x,gan,gen,jum;
cout<<"PROGRAM DERET BILANGAN MENGGUNAKAN FOR"<<endl;cout<<"----------------------"<<endl;cout<<endl;cout<<"Masukkan Jumlah Bilangan : ";cin>> x ;cout<<endl;cout<<endl;gan=1;gen=0;jumgan=0;jumgen=0;cout<<"No."<<setw(13)<<"Ganjil"<<setw(10)<<"Genap"<<endl;cout<<"---"<<setw(13)<<"------"<<setw(10)<<"-----"<<endl;for (i=1 ; i<=x ; i=i+1){cout<<setw(2)<< i <<"."<<setw(10)<<gan <<setw(12)<< gen<<endl;jumgan=jumgan+gan;jumgen=jumgen+gen;gan=gan+2;gen=gen+2;}cout<<setw(10)<<"--------------------------"<<endl;cout<<setw(13)<<jumgan<<setw(12)<<jumgen<<endl;jum=jumgan+jumgen;cout<<endl;cout<<endl;cout<<"Jumlah Ganjil + Jumlah Genap = "<<jum<<endl;getch();}
0 comments:
Post a Comment