Program Deret Angka Berurutan Naik dan Turun C++
Program membuat Deret Angka berurutan naik dari yang terkecil ke terbesar mendatar dan menurun dan berurutan turun inputan sesuai keinginan user. 1, 2, 3, 4, 5, 4, 3, 2, 1. . . .dengan perulangan C++.
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
main() {
{
int i, j, fl, stat=1, y, x;
while (stat!=0){
clrscr();
cout<<"\nDeret Angka \n\n";
cout<<"=============================\n";
cout<<"Input jumlah baris/angka : ";cin>>stat;
if(stat==0){
break;
}
x=stat/2;
if(stat%2==0){
if(x%2==0){
x=x-1;
}else{
x=x-1;
}
}
for(j=0;j<stat;j++){
if(j<=x){
for(i=0;i<=j;i++){
cout<<i+1<<"";
}
cout<<endl;
}else{
for(i=stat;i>j;i--){
cout<<i-j<<"";
}
cout<<endl;
}
}
getch();
}
cout<<"bye-bye";
getch(); }
}
///////
screen shoot :
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
main() {
{
int i, j, fl, stat=1, y, x;
while (stat!=0){
clrscr();
cout<<"\nDeret Angka \n\n";
cout<<"=============================\n";
cout<<"Input jumlah baris/angka : ";cin>>stat;
if(stat==0){
break;
}
x=stat/2;
if(stat%2==0){
if(x%2==0){
x=x-1;
}else{
x=x-1;
}
}
for(j=0;j<stat;j++){
if(j<=x){
for(i=0;i<=j;i++){
cout<<i+1<<"";
}
cout<<endl;
}else{
for(i=stat;i>j;i--){
cout<<i-j<<"";
}
cout<<endl;
}
}
getch();
}
cout<<"bye-bye";
getch(); }
}
///////
screen shoot :
kalau gini gimana kak?
ReplyDeleteInput = 5
1
12
123
12345
1234
123
12
1