Programowanie cwiczenia zjazd VII 18 12 2011


#include

using namespace std;

int suma(int a[], int n)
{
int suma = 0;

for (int i=0; i<5; i++)
{
suma += a[i];
}
return suma;
}

int main()
{
int a[] = {1, 5, 8, 10, 12};

for (int i=0; i<5; i++)
{
cout << a[i] << endl;
}

cout << "Suma elementow = " << suma(a,5) << endl;
}


*******************************************************************************************************
#include

using namespace std;

int suma(int a[], int n)
{
int suma = 0;

for (int i=0; i {
suma += a[i];
}
return suma;
}

int iloczyn(int a[], int n)
{
int iloczyn = 1;

for (int i=0; i {
if (a[i] % 2 ==0)
iloczyn *= a[i];
}
return iloczyn;
}

int main()
{
int a[] = {1, 2, 9, 10, 13};

cout << "Suma elementow = " << suma(a,5) << endl;
cout << "Iloczyn elementow parzystych = " << iloczyn(a,5) << endl;
}

*******************************************************************************
#include
#include
#include

using namespace std;

void randomize()
{
srand(time(0));
}

double random(double min, double max)
{
return rand()/(double)RAND_MAX*(max-min+1)+min;
}

void losuj(double tab[], int n)
{
for (int i=0; i {
tab[i] = random(-10,10);
}
}

void print(double tab[], int n)
{
cout << "[ ";
for (int i=0; i {
cout << setw(10) << tab[i];
}
cout << " ]" << endl;
}


int main()
{
randomize();
double tab[5];
losuj(tab,5);
print(tab,5);

}
**********************************************************************************

#include
#include
#include

using namespace std;

void randomize()
{
srand(time(0));
}

double random(double min, double max)
{
return rand()/(double)RAND_MAX*(max-min+1)+min;
}

void losuj(double tab[], int n)
{
for (int i=0; i {
tab[i] = random(-10,10);
}
}

void print(double tab[], int n)
{
cout << "[ ";
for (int i=0; i {
cout << setw(10) << tab[i];
}
cout << " ]" << endl;
}

double iloczyn(double a[], double b[], int n)
{
double suma = 0;
for (int i=0; i {
suma += a[i]*b[i];
}
return suma;
}


int main()
{
randomize();
double tab[5];
double tab2[5];
losuj(tab,5);
losuj(tab2,5);

print(tab,5);
print(tab2,5);

cout << "iloczyn = " << iloczyn(tab,tab2,5) << endl;

}


****************************************************************************************************

#include
#include
#include

using namespace std;

void randomize()
{
srand(time(0));
}

double random(double min, double max)
{
return rand()/(double)RAND_MAX*(max-min+1)+min;
}


int main()
{
string s = "Ala studiuje na ATH w Bielsku-Bialej";

int spacja = 0;

for (int i=0; i {

if ( s[i] == ' ')
spacja++;
}

cout << "Wyrazow jest " << spacja+1 << endl;
}

********************************************************************************************

#include
#include
#include

using namespace std;

const int nmax=10;

void randomize()
{
srand(time(0));
}

double random(double min, double max)
{
return rand()/(double)RAND_MAX*(max-min+1)+min;
}

void losuj(int tab[nmax][nmax], int n, int m)
{
for (int i=0; i {
for (int j=0; j {
tab[i][j] = random(-10,10);
}
}
}

void print(int tab[nmax][nmax], int n, int m)
{
for (int i=0; i {
for (int j=0; j {
cout << setw(5) < }
cout << endl;
}
}




int main()
{
randomize();
int tab[nmax][nmax];

losuj(tab,4,4);
print(tab,4,4);

}
******************************************************************************************

#include
#include
#include

using namespace std;

const int nmax=10;

void randomize()
{
srand(time(0));
}

double random(double min, double max)
{
return rand()/(double)RAND_MAX*(max-min+1)+min;
}

void losuj(int tab[nmax][nmax], int n, int m)
{
for (int i=0; i {
for (int j=0; j {
tab[i][j] = random(-10,10);
}
}
}

void add(int a[nmax][nmax], int b[nmax][nmax], int c[nmax][nmax], int n, int m)
{

}



void print(int tab[nmax][nmax], int n, int m)
{
for (int i=0; i {
for (int j=0; j {
cout << setw(5) < }
cout << endl;
}
}


void razy_dwa(int tab[nmax][nmax], int n, int m)
{
for (int i=0; i {
for (int j=0; j {
cout << setw(5) <<2*tab[i][j];
}
cout << endl;
}
}



int main()
{
randomize();
int tab[nmax][nmax];

losuj(tab,3,3);

print(tab,3,3);

razy_dwa(tab,3,3);

}


Wyszukiwarka

Podobne podstrony:
Programowanie ćwiczenia zjazd IV 06 11 2011
Programowanie ćwiczenia zjazd 3 23 10 2011
PROGRAM CWICZEN Z CHEMII ORGANICZNEJ BIOLOGIA 2010 2011
zad kol1 18 12 2011
Programowanie zjazd VIII 15 01 2011
ANDRAGOGIKA program ćwiczeń 11 12
Tygodnik nrh  18 12 r
Program ćwiczeń laboratoryjnych
program cwiczen z mechaniki budowli 1
Pomoc Życiowa nr2 (12 2011)
PRAWO WYKLAD VII 06 02 2011 1
18 12 06

więcej podobnych podstron