Similar presentations:
One dim. array
1. masivebi
• I. erTganzomilebiani masivi: A={a0 , a1 , . . ., an }A
a0
a1
...
...
II. organzomilebiani masivi: A=
...
...
...
...
...
...
an
2. erTganzomilebiani masivis gamocxa-deba da elementebiT Sevseba
erTganzomilebiani masivis gamocxadeba da elementebiT Sevsebamasivis tipi da saxeli [elem. raodenoba] ;
mag. int b[15], i;
for(i=0;i<15;i++)
cin>>b[i];
analogiurad xdeba gamotana:
for(i=0;i<15;i++)
cout<<b[i]<<“ “;
3. SemTxveviTi ricxvebis generireba
funqcia rand ( ) realizebulia cstdlib biblioTekaSi. miiReba ricxvi [0;Rand_Max-1] diapazonidan. Rand_Max =32767.
rand()%n-s SemTxvevaSi diapazoni iqneba [0;n-1];
rand()%n-k SemTxvevaSi diapazoni iqneba [-k;n-k-1];
rand()%n+k SemTxvevaSi diapazoni iqneba [k;n+k -1];
mag. d=rand()%17-5; ricxvi iqneba [-5; 11] diapazonidan.
4. funqcia srand.
zogadi saxiT Caiwereba srand (argumenti); misidaniSnulebaa rand() funqciisaTvis sawyisi monacemis
gamomuSaveba.
srand(time(0)); - argumentad aqvs mimdinare dro
kompiuterSi. uzrunvelyofs programis yoveli gaSvebisas
gansxvavebuli SemTxveviTi ricxvis miRebas.
time(0) realizebulia ctime biblioTekaSi.
# include<iostream>
# include<cstdlib>
# Include<ctime>
. . . . . . . . . . .
srand(time(0));
5. ერთგანზომილებიანი მასივის (ვექტორის) ელემენტების შეტანა/გამოტანა
#include <iostream>ერთგანზომილებიანი მასივის
(ვექტორის) ელემენტების
შეტანა/გამოტანა
using namespace std;
int main()
{
double a[15], s=0,sa;
int i,k=0;
for (i=0;i<15;i++)
cin>>a[i];
cout<<endl<<endl;
for (i=0; i<15; i++)
cout<<a[i]<<" ";
cout<<endl;
for(i=0;i<15;i++)
if(a[i]>0) {s+=a[i]; k++;}
sa=s/k;
cout<<“sashualo=“<<sa<<endl;
system ("pause");
return 0;
}
6. mag.1. mocemuli C={c0,c1, . . . ,cn} n≤25 veqtoris udidesi mniSvn-bis mqone elementis povna.
# include <iostream>using namespace std;
int main ()
{
double c[26], max; int n, i;
cin>>n;
for (i=0 ; i<n ; i++)
cin>>c[i] ;
max=c[0];
for (i=1 ; i<n ; i++)
if (c[i]>max) max=c[i];
cout<<endl<<”max=”<<max;
system(“pause”);
return 0;
}
7. mag.2. B={b0,b1,. . . ,b14} veqtoris dadebiTi elementebis jamis gamoTvla.
# include <iostream>using namespace std;
main ()
{
double b[15], sum; int i;
for (i=0 ; i<15 ; i++)
cin>>b[i] ;
sum=0;
for (i=0 ; i<15 ; i++)
if (b[i]>0) sum+=b[i];
cout<<endl<<”sum=”<<sum;
system(“pause”);
return 0;
}
8. mag.3. C={c0,c1, . . . ,ck} k≤22 veqtoris aranulovani elementebis saSualo ariTmetikulis gamoTvla.
mag.3. C={c 0,c 1, . . . ,c k} k≤22 veqtoris aranulovanielementebis saSualo ariTmetikulis gamoTvla.
# include <iostream>
using namespace std;
main ()
{
double c[23], sum=0,sa;
int i,n=0,k;
cin>>k;
for (i=0 ; i<k ; i++)
9. mag.4. C={c0,c1, . . . ,cn} n≤24 veqtoris dadebiT elementebs Soris umciresi mniSvnelobis mqone elementis rigiTi nomris gamoTvla.
# include <iostream>using namespace std;
main ()
{
double c[25], min=1e+06;
int i,k,n;
cin>>n;
for (i=0 ; i<n ; i++)
10. mag.5. D={d0,d1, . . . ,dn} n≤24 veqtoris luwindeq-siani, nulisagan gansxvavebuli elementebis namravlis gamoTvla.
# include <iostream>using namespace std;
int main ()
{
double d[25], p=1; int i,n;
cin>>n;
for (i=0 ; i<25 ; i++)
cin>>d[i] ;
for (i=2 ; i<25 ; i+=2)
if (d[i]>0) p*=d[i];
cout<<endl<<"product="<<p<<endl;
system ("pause");
return 0;
}
11. mag.6. mocemuli D={d0,d1, . . . ,dn} n≤15 veqtoris luwi mniSvnelobis mqone elementebisagan axali K={k0,k1, . . . ,kn} n≤15 veqtoris miReba da gamotana ekranze.
DK
-15
24
0
-30
45
24
-30
56
8
44
56
19
0
8
44
12.
# include <iostream>using namespace std;
int main ()
{
int d[15],k[15], i,j=0,n;
cin>>n;
for (i=0 ; i<n ; i++)
cin>>d[i] ;
for (i=0 ; i<n ; i++)
if (d[i]!=0 && d[i]%2==0) {k[j]=d[i];j++;}
cout<<"\n\n satskisi D masivi: "<<endl;
for (i=0 ; i<n ; i++)
cout<<d[i]<<" ";
cout<<"\n\n migebuli K masivi:\n";
for (i=0 ; i<j ; i++)
cout<<k[i]<<" ";
cout<<'\n';
system ("pause");
return 0;
}
13. მასივის დალაგება „ამორჩევის“ მეთოდით
01
2
3
4
5
6
23
15
31
9
17
8
19
0
8
15
31
9
17
23
19
1
8
9
31
15
17
23
19
2
8
9
15
31
17
23
19
8
9
15
17
31
23
19
8
9
15
17
19
23
31
8
9
15
17
19
23
31
3
4
5
14.
# include <iostream>using namespace std;
int main ()
{int a[15], i,j,n,min,k,r;
cin>>n;
for (i=0 ; i<n ; i++)
cin>>a[i] ;
for (i=0;i<n-1;i++)
{ min=a[i];k=i;
for (j=i+1; j<n;j++)
if(a[j]<min){min=a[j];k=j;}
if (k!=i){r=a[k]; a[k]=a[i]; a[i]=r;}
15. მასივის დალაგება “ჩაძირვის” მეთოდით
# include <iostream>using namespace std;
int main ()
{ int a[15], i,j,n,i1,r;
cin>>n;
for (i=0 ; i<n ; i++)
cin>>a[i] ;
cout<<"\n\n satskisi A masivi: "<<endl;
for (i=0 ; i<n ; i++)
cout<<a[i]<<" ";
cout<<'\n';
for (i=0;i<n-1;i++)
for (j=0; j<n-1-i;j++)
if(a[j]>a[j+1]){r=a[j]; a[j]=a[j+1]; a[j+1]=r;}
cout<<"\n\n dalagebuli A masivi:\n";
for (i=0 ; i<n ; i++)
cout<<a[i]<<" ";
cout<<'\n';
system ("pause");
return 0;
}