Home > Uncategorized > For pada C++ part 3

For pada C++ part 3

Program berikut ini akan melakukan perhitungan nilai total terhadap sejumlah data yang dimasukan.

#include <iostream.h>

void main()


int n, data;

long hasil = 0;

cout << “Jumlah data :”;

cin >> n;

for (int i=0 ; i < n; i++){

cout << “Data ke-“<<i+1<<“:”;

cin >> data;

hasil += data;


cout <<“Jumlah Total Data:” << hasil << endl;


Dan ouputnya adalah:

Jumlah data : 4

Data ke-1:4

Data ke-2:4

Data ke-3:3

Data ke-4:1

Jumlah Total Data:12

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: