Wednesday 24 December 2014

PROGRAM SEGITIGA KEBAWAH C++

  #include <cstdlib>
   #include <iostream>
   #include <iomanip>
   using namespace std;
   int main(int argc, char *argv[])
   {
    int n=12;
    int baris=n/2;
    int hasil;
    int total=0;
    int k;
    for (int i=baris;i>=2;i--)
   {
        hasil=0;k=10;
        for(int j=2;j<=i;j++)
   {
        hasil=hasil+k;
        cout<<k;
        if (j==i)
        cout<<"  ";
    else
        cout<<" + ";
        k=k-2;    
    }
       cout<<setiosflags(ios::right)<<setw(10)<<" = "<<hasil<<endl;
       total=total+hasil;
    }
       cout<<setiosflags(ios::right)<<setw(10)<<" total = "<<total<<endl;
       cout<<endl;
       system("PAUSE");
       return EXIT_SUCCESS;
    }

No comments:

Post a Comment