SOAL 3
unknown
c_cpp
4 years ago
628 B
10
Indexable
#include<iostream> using namespace std; int main() { // KAMUS int i, x, N, jumlah; // ALGORITMA cout << "-------------------------------------" << endl; cout << "| JUMLAHKAN SEMUA BILANGAN GANJIL |" << endl; cout << "-------------------------------------" << endl; cout << "Masukkan bilangan N maksimal : "; cin >> N; cout << "Jumlah semua bilangan ganjil 1-" << N << " : " << endl; for(int i = 1; i <= N; i++) { if ( i % 2 != 0 ) { cout << i <<" "; } } for(x = 0; x <= N; x++) { if(x % 2 !=0) { jumlah = jumlah + x; } } cout << "= " << jumlah; }
Editor is loading...