YouGoDe WebMaster
Numri i postimeve : 2345 Registration date : 06/08/2008 Age : 43 Location : YouGoDe.Org
| Titulli: Detyra provimi ne C++ 31.03.11 11:32 | |
| Ketu do te keni disa detyra bashke me gjithe zgjedhjet e tyre te punuara ne C++, qe kane qene ne provime neper fakultete te ndryshme:Detyra I - Cito :
- *** DETYRA 1 ****
************************************************** ************************* #include using namespace std;
/////////////////////////DETYRA 1/////////////////////////////////////////// // 1. Shkruani funksion qė do t'i shtyp tė gjithė numrat e pėrsosur prej 2 // deri nė N. Numri ėshtė i pėrsosur nėse ėshtė i barabartė me shumėn e // pjesėtuesve tė tij duke e pėrjashtuar vetė numrin. // // P.sh. Numri 28 ėshtė i pėrsosur pasi: 28 = 1+2+4+7+14 //////////////////////////////////////////////////////////////////////////
bool persosur(int m);
int main() { int i, N;
//Se pari lexojme numrin N nga tastatura cout << "Jepni numrin N: "; cin >> N;
//Kalojme gjithe numrat prej 2 deri N, ashtu sic kerkon detyra //Nese numri eshte i persosur, e shtypim //Per ta provuar nese numri eshte i persosur, do ta perdorim funksionin //'persosur', te deklaruar me lart for(i = 2; i <= N; i++) if ((persosur(i) == true)) cout << i << endl;
return 0; }
bool persosur(int m) { // Ky funksion merr nje numer 'm' dhe kthen 'true' (e sakte) nese numri eshte // i persosur. Nese numri nuk eshte i persosur kthen 'false' (jo e sakte)
int S = 0; //Shuma e pjesetuesve int i;
//Kalojme te gjithe numrat nga 1 deri m-1 dhe shofim nese numri 'm' //eshte i plotepjesetueshem me to. Nese po, ia shtojme shumes. for (i = 1; i <= m - 1; i++) { if (m % i == 0) S = S + i; }
//Nese shuma e fituar eshte e barabarte me numrin 'm', atehere numri 'm' //eshte i persosur if (m == S) return true; else return false; } Detyra II
- Cito :
- #include
using namespace std;
////////////////////////DETYRA 2/////////////////////////////////////// // 2. Pėr njė vektor a[10] tė shkruhet program i cili do t'a caktojė // numrin e elementeve tė vektorit qė kanė nė "anėn e djathtė" numėr mė // tė madh se vetja. // // P.sh. pėr vektorin a: 4, 8, -3, 7, -2, -13, 10, 20, 2, 1 // Dalje: // 4 -3 -13 10 // Rezultati ėshtė 4
int main() { int N = 10; //Deklarimi i vektorit int A[10] = {4, 8, -3, 7, -2, -13, 10, 20, 2, 1}; int num = 0; //numeruesi int i;
//Per te pare se cili numer ka ne anen djathte numer me te madh se vetja, //duhet ate numer t'a krahasojme me numrin qe ka indeks per nje me te madh //ne vektor. Psh. numri i katert ne vektor, ne anen e djathte e ka numrin e //peste, i shtati te tetin e keshtu me rradhe. Ndalemi te anetari i //parafundit, pasi anetari i fundit nuk ka asgje ne te djathte
for (i = 0; i < N -1; i++) { if (A[i+1] > A[i]) { //Nese plotesohet kushti, e shtypim numrin dhe rritim numeruesin cout << A[i] << " "; num++; } }
//Shtypim numeruesin cout << endl; cout << "Rezultati eshte " << num; } Detyra III
- Cito :
- #include
using namespace std;
////////////////////////////DETYRA 3///////////////////////////////////////// // Shkruani funksion pėr formim tė vektorit a[n] nga shifrat e numrit x qė // lexohet nga tastiera. Elementet e vektorit duhet tė kanė radhitje inverze // me shifrat e numrit. (x < 1 000 000). // // P.sh. pėr numrin 89756 // Dalje: // Numri=89756 // a[0]=6 a[1]=5 a[2]=7 a[3]=9 a[4]=8
int formoV(int A[], int n);
int main() { int N; //numri qe jepet int A[10]; //E deklarojme si vektor me 10 elemente, pasi nuk presim qe // numri i dhene te kete me shume se 10 shifra int madhesia; //Madhesia e vektorit te formuar int i;
cin >> N; madhesia = formoV(A, N);
//Shtyp vektorin e porsaformuar for (i = 0; i < madhesia; i++) { cout << "A[" << i << "]=" << A[i] << " "; } }
int formoV(int A[], int n) { //Ky funksion formon vektorin A nga shifrat e numrit n te kthyer mbrapsht //Si rezultat kthen madhesine e vektorit te formuar int i = 0; int shifra;
//Vektorin e formojme duke i nxjerrur shifrat nga fundi i numrit while (n > 0) { shifra = n % 10; n = n /10; A[i] = shifra; i++; }
return i; } Detyra IV
- Cito :
- #include
using namespace std;
/////////////////////////DETYRA 4///////////////////////////////////////////// // Shkruani funksion qė pėr njė matricė A[4][4] do t'a caktojė rreshtin // qė ka shumė mė tė madhe tė elementeve. // // P.sh. pėr matricėn A: // 4 5 8 2 // 13 -5 6 1 // 9 6 -7 4 // 12 -3 1 0 // Dalje: // Rreshti me shumė mė tė madhe: 0 // Shuma=19
int shumaRreshtit(int A[4][4], int r);
int main() { //Deklarimi dhe inicializimi i matrices int A[4][4] = {{4, 5, 8, 2}, {13, -5, 6, 1}, {9, 6, -7, 4}, {12, -3, 1, 0}};
int i, s; int smax; //Shuma me e madhe int imax; //indeksi i rreshtit me shume me te madhe
//Se pari e marrim rreshtin 0 si me shume me te madhe smax = shumaRreshtit(A, 0); imax = 0;
//Pastaj kalojme gjithe rreshtat tjere. Nese gjejme ndonje me shume me te //madhe, atehere do ta mbajme mend ate rresht for (i = 1; i < 4; i++) { s = shumaRreshtit(A, i); //shuma e rreshtit i if (s > smax) { smax = s; imax = i; } }
//Shtyp rezultatin cout << "Rreshti me shume me te madhe: " << imax << endl; cout << "Shuma= " << smax; }
int shumaRreshtit(int A[4][4], int r) { //Ky funksion llogarit shumen e rreshtit 'r' ne matricen 'A' int j; int S = 0; for (j = 0; j < 4; j++) S = S + A[r][j];
return S; } Detyra V - Cito :
- #include
using namespace std;
//////////////////////////DETYRA 5///////////////////////////////////////////// // Matrica A[3][5] i pėrmban notat e tre studentėve nga pėsė lėndė. Shkruani // njė funksion qė do tė formojė vektorėt: s - pėr suksesin mesatar tė // secilit student; l - pėr suksesin mesatar tė arritur nė secilėn lėndė. // // P.sh. pėr matricėn A: // 8 9 9 10 6 // 9 10 8 10 8 // 10 10 10 10 10 // Dalje: // Suksesi i studentėve: // s[0]=8.40 s[1]=9.00 s[2]=10.00 // Suksesi nė lėndėt: // l[0]=9.00 l[1]=9.67 l[2]=9.00 l[3]=10.00 l[4]=8.00
void studentet (int notat[3][5], double s[]); void lendet(int notat[3][5], double l[]);
int main() { //Deklarimi dhe inicializimi i matrices int A[3][5] = {{8, 9, 9, 10, 6}, {9, 10, 8, 10, 8}, {10, 10, 10, 10, 10}}; double s[3]; //Vektori i mesatareve te studenteve double l[5]; //Vektori i mesatareve te lendeve int i; //Thirja e funksioneve studentet(A, s); lendet(A, l);
//Shtypja e rezultateve cout << "Suksesi i studenteve:"< for(i = 0; i < 3; i++) cout << "s[" << i <<"]=" << s[i] << " ";
cout << endl; cout << "Suksesi ne lendet:" << endl; for (i = 0; i < 5; i++) cout << "l[" << i << "]=" << l[i] << " "; }
void studentet (int notat[3][5], double s[]) { //Ky funksion llogarit notat mesatare te cdo studenti //dmth mesataren e cdo rreshti dhe e rruan ne vektorin 's' int i, j; int shuma; //Shuma e notave ne cdo rresht
//Kalo cdo rresht for (i = 0; i < 3; i++) { shuma = 0; for (j = 0; j < 5; j++) shuma = shuma + notat[i][j]; //Mesatarja s[i] = shuma / 5; } return; }
void lendet(int notat[3][5], double l[]) { //Ky funksion llogarit notat mesatare ne cdo lende //dmth mesataren e cdo kolone dhe e rruan ne vektorin 'l' //Ketu duhet vektorin ta kalojme kolone per kolone int i, j; int shuma; //Shuma e notave ne cdo colone
//Kalo cdo kolone for (j = 0; j < 5; j++) { shuma = 0; for (i = 0; i < 3; i++) shuma = shuma + notat[i][j]; //Mesatarja l[j] = shuma / 3; } return; } | |
|