Catatan Minggu 4

Mengganti atau mengedit nilai indeks array c++

#include <iostream>

#define maks 5
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void cetak (int a[]){
int cari;
        for(int i=0; i<5; i++){
       
        cout<<"masukan data "<<"["<<i<<"] :";
        cin>>a[i];
    }
   
    for (int i=0; i<5; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    cout<<"masukan angka yang diganti:";cin>>cari;
    int x=0;

    cout<<"hasil setelah diganti : ";cout<<endl;
        for (int i=0; i<5; i++)
       
           
        if(a[i]==cari){
            x=1;
            cout<<"masukan angka pengganti: ";cin>>a[i];
            for (int i=0; i<5; i++){
        cout<<a[i]<<" ";
    }
        }
        if(x==0)
{cout<<"Data yang anda masukkan salah";
}


    }
   
int main(){
    int b[5];
    cetak(b);

return 0;
}

Share this:

ABOUT THE AUTHOR

Hello We are OddThemes, Our name came from the fact that we are UNIQUE. We specialize in designing premium looking fully customizable highly responsive blogger templates. We at OddThemes do carry a philosophy that: Nothing Is Impossible

0 komentar:

Posting Komentar