You are on page 1of 9

Nama : Fakhri Afif

Kelas : 1 D4 Mekatronika A

NRP : 3110171014

-------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>

using namespace std;

using std::cout;

using std::endl;

#include <iomanip>

using std::setw;

int main()

const int arraySize = 10;

int n[arraySize] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int total=0;

for(int i=0; i<arraySize; i++)

total+=n[i];

cout<<"Total of array element value is"<<total<<endl;

return 0;
}

--------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>

using namespace std;

using std::cout;

using std::endl;

#include <iomanip>

using std::setw;

int main()

const int arraySize = 10;

int n[arraySize] = {19, 3, 15, 7, 11, 9, 13, 5, 17, 1};


cout << "Element" << setw(13) << "Value"

<< setw(17) << "Histogram" << endl;

for(int i=0; i<arraySize; i++)

cout << setw(7) << i << setw(13)

<< n[i] << setw(9);

for (int j=0; j<n[i]; j++)

cout << "*";

cout << endl;

return 0;

--------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>
using namespace std;

using std::cout;

using std::endl;

#include <iomanip>

using std::setw;

#include <cstdlib>

#include <ctime>

int main()

const int arraySize = 7;

int f[arraySize] = {0};

srand(time(0));

for(int roll=0; roll<=6000; roll++)

++f[1+rand()%6];

cout<<"face"<<setw(13)<<"Frequency"<<endl;

for (int face =1;face<arraySize;face++)

cout<<setw(4)<<face

<<setw(13)<<f[face]<<endl;

return 0;

}
--------------------------------------------------------------------------------------------------------------------------------------

#include <iostream>

using namespace std;

using std::cout;

using std::endl;

#include <iomanip>

using std::setw;

int main()

const int responseSize = 40;

const int frequencySize = 11;

int responses[responseSize]={1, 2, 6, 4, 8, 5, 9, 7, 8,

10, 1, 6, 3, 8, 6, 10, 3, 8, 2, 7, 6, 5, 7, 6, 8, 6, 7,
5, 6, 6, 5, 6, 7, 5, 6, 4, 8, 6, 8, 10 };

int frequency[frequencySize]={0};

for (int answer=0;answer<responseSize;answer++)

++frequency[responses[answer]];

cout<<"Rating"<<setw(17)<<"frequency"<<endl;

for(int rating=1;rating<frequencySize;rating++)

cout<<setw(6)<<rating

<<setw(17)<<frequency[rating]<<endl;

return 0;

----------------------------------------------Mencari Mean--------------------------------------------------------------------

#include <iostream>

using namespace std;

using std::cout;

using std::endl;
#include <iomanip>

using std::setw;

int main()

const int arraySize = 10;

int n[arraySize] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int total=0;

float rata=0;

for(int i=0; i<arraySize; i++)

total+=n[i];

cout<<"Hasil Elemen adalah = "<<total<<endl;

rata= total/10.0;

cout<<"rata ratanya adalah "<<rata<<endl;

return 0;

}
----------------------------------------------Mencari Median------------------------------------------------------------------

#include <iostream>

using namespace std;

using std::cout;

using std::endl;

#include <iomanip>

using std::setw;

int main()

const int b = 10;

int a[b] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int total=0;
float median;

for(int i=0; i<b; i++)

if(b%2==0){

median=(a[(b/2)]+a[(b/2)-1])/2.0;

else{

median= a[(b/2)];

cout<<"Median dari data tersebut adalah = "<<median<<endl;

return 0;

You might also like