Dev C++
source code :
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
float angka, total = 0, rata;
int jumlah;
cout << "1. Mencari Rata-rata. (jumlah angka ditentukan)" << endl;
cout << endl;
cout << "masukkan jumlah angka : "; cin >> jumlah;
cout << endl;
for (int i = 1; i <= jumlah; i++) {
cout << "Masukkan angka : "; cin >> angka;
total = total + angka;
}
cout << endl;
cout << "Total : " << total << endl;
rata = total / jumlah;
cout << "Rata-rata : " << rata;
return 0;
}
outputnya :
2. Mencari nilai max, min dan rata
Dev C++
source code :
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int x[100],n,max,min,i;
double a,b;
cout<<"Masukkan Banyaknya Data : ";cin>>n;
for (i=0;i<n;i++)
{
cout<<"Masukan Nilai " <<i+1<<" : ";cin>>x[i];
}
max = x[0];
min = x[0];
for (i=0;i<n;i++)
{
if (max < x[i])
{
max = x[i];
}
if (min > x[i])
{
min = x[i];
}
}
cout<<"Nilai tertinggi = "<<max<<endl;
cout<<"Nilai terendah = "<<min<<endl;
a=0;
for (int i=0;i<n;i++)
{
a=a+x[i];
}
b=a/n;
cout<<"Rata-Rata : "<<a<<"/"<<n<<" = "<<b<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
outputnya :
3. Mencari nilai pangkat
Dev C++
source code :
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int kali(int i, int n, int p){
if(i<=n)
return p*kali(i+p,n,p);
}
int main(int argc, char** argv) {
int x,y,i=0;
cout<<"menghitung hasil perpangkatan\n";
cout<<"nilai pertama:";cin>>x;
cout<<"masukan hasil pangkat:";cin>>y;
cout<<"hasil="<<kali(i,y,x);
return 0;
}
outputnya :
Tidak ada komentar:
Posting Komentar