#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 argc, char** argv) {
int n,i;
float num[10], sum, average;
cout<<" masukan data : ";
cin>>n;
for(i=1;i<=n;++i){
cout<<endl<<i+1<<"masukan no : ";
cin>>num[i];
sum+=num[i];
}
cout<<endl<<"sum = "<<sum;
average=sum/n;
cout<<endl<<"average = "<<average;
return 0;
}
7.2
#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 argc, char** argv) {
int n,i;
float num[10], sum, average;
cout<<" masukan data : ";
cin>>n;
for(i=1;i<=n;++i){
cout<<endl<<i+1<<"masukan no : ";
cin>>num[i];
sum+=num[i];
}
cout<<endl<<"sum = "<<sum;
average=sum/n;
cout<<endl<<"average = "<<average;
return 0;
}
7.3
#include <iostream>
using namespace std;
int main()
{
int max,n,i,min;
float A[100];
cout<<"\t\tProgram Menentukan Bilangan terbesar\n\n";;
cout <<"Masukkan Jumlah Data : ";cin>>n;
for(i=0;i<n;i++){
cout << "masukkan bilangan ke "<< i+1 << " : ";
cin >> A[i];}
max = A[0];
for (i=1;i<n;i++){
if (max < A [i])
max = A[i];
}
cout <<"\n\nNilai Terbesar adalah : "<<max<<endl;
return 0;
}
7.4
#include <iostream>
using namespace std;
int main()
{
int max,n,i,min;
float A[100];
cout<<"\t\tTerbesar dan Terkecil\n\n";
cout <<"Masukkan Jumlah Data : ";cin>>n;
for(i=0;i<n;i++){
cout << "masukkan bilangan ke "<< i+1 << " : ";
cin >> A[i];}
max = A[0];
min = A[0];
for (i=1;i<n;i++){
if (max < A [i])
max = A[i];
if (min > A [i])
min = A[i];
}
cout <<"Nilai Terbesar adalah : "<<max<<endl;
cout <<"Nilai Terkecil adalah : "<<min<<endl;
return 0;
}
7.5
#include <iostream>
#include <conio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int x;
void findmod(float bil[], int n, float mod[]){
int total[100];
int k=1;
x=0;
for(int c=0;c<n;c++){
for(int i=(n-1);i>=0;i++){
if(bil[i]<bil[i-1]){
int temp;
temp=bil[i];
bil[i]=bil[i-1];
bil[i-1]=temp;
}
}
}
for(int c=0;c<n;c++){
total[c]=0;
for(int i=0;i<n;i++){
if(bil[c]==bil[i]){
total[c]++;
}
}
}
for(int c=0;c<n;c++){
if(total[c]>k){
k=total[c];
}
}
for(int c=0;c<n;c++){
if(x==0)
mod[x]=0;
else
mod[x]=mod[x-1];
if(total[c]==k){
if(bil[c]!=mod[x]){
mod[x]=bil[c];
x++;
}
}
}
int z=0;
for(int c=0;c<n;c++){
if(total[c]==k){
z++;
}
}
if(z==n){
x=0;
}
}
int main(){
int n;
float bil[100];
float mod[100];
cout<<" Banyak N : ";
cin>>n;
for(int c=0;c<n;c++){
cout<<"nilai "<<(c+1)<<" : ";
cin>>bil[c];
}
cout<<endl;
findmod(bil,n,mod);
if(x==0)
cout<<"tidak ada modus!"<<endl;
else{
cout<<"Modus : ";
for(int c=0;c<x;c++){
cout<<mod[c]<<" ";
}
}
return 0;
}
7.6
#include <iostream>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
char kata[15];
int belakang;
bool palindrom = true;
cout<<"masukan kata : ";
cin.getline(kata, sizeof(kata));
int panjang = strlen(kata);
belakang = panjang-1;
for(int a=0;a<panjang;a++){
if((char)tolower(kata[a])!=(char)tolower(kata[belakang])){
palindrom = false;
break;
}
belakang--;
}
if(palindrom){
cout<<"termasuk palindrom";
cout<<endl;
}
else
cout<<" bukan palindrom";
return 0;
}