Minggu, 02 November 2014

Membuat Program perulangan dengan C++

Berikut ini adalah contoh program untuk menampilkan sebuah angka secara bertingkat menggunakan C++.
Selamat mencoba dan semoga bermanfaat!

Program I :

#include <iostream.h>
#include <conio.h>
main() {
int a;
cout<<"Masukkan batas : ";cin>>a;
for ( int b=a; b>=1; b--)
            {
            for(int i=b;i>=1;i--)
                        {
            cout<<b*i<<" ";
            }
            cout<<endl;
            }

  getch();}




Program II :

#include <iostream.h>
#include <conio.h>

main() {
int a;
cout<<"\nMasukkan batas : ";cin>>a;

for ( int b=1; b<=a; b++)
            {
   cout<<endl;
            for(int i=1;i<=b;i++)
            {
            cout<<" * ";
            }
            }
getch();}




0 komentar:

Posting Komentar

 
Copyright © . Explore Ilmu - Posts · Comments
Theme Template by BTDesigner · Powered by Blogger