#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int a[20], i, j, k ,n;
cout<<" enter aray size : ";
cin>>n;
cout<<" enter aray "<<n<<" elemen : \n";
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<" new aray elemen are : ";
for(i=0;i<n;i++){
for(j=i+1;j<n;){
if(a[j]==a[i]){
for(k=j;k<n;k++){
a[k]=a[k+1];
}
n--;
}
else{
j++;
}
}
}
for(i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
SUBPROGRAM :
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void masuk(int a[20]){
int i,n,j,k;
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<" new aray elemen are : ";
for(i=0;i<n;i++){
for(j=i+1;j<n;){
if(a[j]==a[i]){
for(k=j;k<n;k++){
a[k]=a[k+1];
}
n--;
}
else{
j++;
}
}
}
for(i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
int main(int argc, char** argv) {
int a[20], i, j, k ,n;
cout<<" enter aray size : ";
cin>>n;
cout<<" enter aray "<<n<<" elemen : \n";
masuk(a);
}
0 komentar:
Posting Komentar