Kamis, 31 Maret 2016

menampilkan jumlah bilangan (1+2+...+N)

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main() {
    int N,i,jumlah;
    jumlah=0;
    cout<<"\t\t----------------------------------------\n";
    cout<<" \t\t menampilkan jumlah bilangan (1+2+..+N) "<<endl;
    cout<<"\t\t----------------------------------------\n\n";
    cout<<" masukan nilai N : ";cin>>N;
    cout<<endl;
    for(int i=1; i<=N; i++){
    cout<<i<<" ";
    jumlah=jumlah+i;   
    }
   
    cout<<"jumlah deret ="<<jumlah;
   
    return 0;
}

Tidak ada komentar:

Posting Komentar