kan udah 5 program kondisional , sekarang ane mau lanjutin 5 porgram perulangan c++ menggunakan bahasa C++.
langsung di coba , kalo ada yg tdk bisa/tidak mengerti comment aja .
1.
#include<iostream.h>
void main()
{
int a,b;
cout<<"masukkan jumlah baris : ";
cin>>a;
cout<<endl;
for(b=1;b<=a;b++){
cout<<b<<endl;
}
}
void main()
{
int a,b;
cout<<"masukkan jumlah baris : ";
cin>>a;
cout<<endl;
for(b=1;b<=a;b++){
cout<<b<<endl;
}
}
2.
#include<iostream.h>
void main()
{
int a,b,c;
cout<<"masukkan angka : ";
cin>>a;
cout<<endl;
c=0;
for(b=1;b<=a;b++){
c=c+b;
cout<<b;
if(b!=a){
cout<<" + ";
}else{
cout<<" = ";
}
} cout<<c;
}
void main()
{
int a,b,c;
cout<<"masukkan angka : ";
cin>>a;
cout<<endl;
c=0;
for(b=1;b<=a;b++){
c=c+b;
cout<<b;
if(b!=a){
cout<<" + ";
}else{
cout<<" = ";
}
} cout<<c;
}
3.
#include<iostream.h>
void main()
{
int a,b,c;
cout<<"Masukkan angka : ";
cin>>a;
cout<<endl;
for(b=1;b<=a;b++){
for(c=1;c<=b;c++){
cout<<" * ";
}
cout<<endl;
}
}
void main()
{
int a,b,c;
cout<<"Masukkan angka : ";
cin>>a;
cout<<endl;
for(b=1;b<=a;b++){
for(c=1;c<=b;c++){
cout<<" * ";
}
cout<<endl;
}
}
4.
#include<iostream.h>
void main()
{
int a,b,c;
cout<<"Masukkan angka : ";
cin>>a;
cout<<endl;
for(b=a;b>=1;b--){
for(c=1;c<=b;c++){
cout<<" * ";
}
cout<<endl;
}
}
void main()
{
int a,b,c;
cout<<"Masukkan angka : ";
cin>>a;
cout<<endl;
for(b=a;b>=1;b--){
for(c=1;c<=b;c++){
cout<<" * ";
}
cout<<endl;
}
}
5.
#include<iostream.h>
void main() // ini tipe datanya
{
int a,spasi,baris,b;
cout<<"Masukkan baris: ";
cin>>baris;
for(a=1;a<=baris;a++)
{
for(spasi=1;spasi<=baris-a;spasi++)
{
cout<<" ";
}
for(b=1;b<=a;b++)
{
cout<<"* ";
}
cout<<"\n";
}
}
void main() // ini tipe datanya
{
int a,spasi,baris,b;
cout<<"Masukkan baris: ";
cin>>baris;
for(a=1;a<=baris;a++)
{
for(spasi=1;spasi<=baris-a;spasi++)
{
cout<<" ";
}
for(b=1;b<=a;b++)
{
cout<<"* ";
}
cout<<"\n";
}
}