0% found this document useful (0 votes)
7 views5 pages

5

The document contains code snippets in C++ for different programming exercises. These include functions to calculate quotients and remainders, display squares with characters, find the hypotenuse of a right triangle, generate and check random numbers, find the largest random number, and print a name and address.

Uploaded by

Ami Mima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views5 pages

5

The document contains code snippets in C++ for different programming exercises. These include functions to calculate quotients and remainders, display squares with characters, find the hypotenuse of a right triangle, generate and check random numbers, find the largest random number, and print a name and address.

Uploaded by

Ami Mima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

}

5.12
cout << endl;
#include <iostream>
}
using namespace std;

5.9
int main() #include <iostream>

{ using namespace std;

for (int i = 1; i <= 10; i++)

{ int main()

// figura e pare {

for (int j = 1; j <= i; j++) int product = 1;

cout << "*"; for (int i = 1; i <= 15; i += 2)

for (int j = i + 1; j <= 10; j++) {

cout << " "; product *= i;

cout << " "; }

// figura e dyte cout <<”produkti I numrave nga 1 ne 15 eshte: " <<


product << endl;
for (int j = 1; j <= (11 - i); j++)
}
cout << "*";

for (int j = (11 - i) + 1; j <= 10; j++)


#include <iostream>
cout << " ";
#include <iomanip>
cout << " ";
using namespace std;
// figura e trete

for (int j = 1; j < i; j++) 5.19


cout << " "; int main()

for (int j = i; j <= 10; j++) {

cout << "*"; double pi = 0;

cout << " "; bool sign = true;

// figura e katert cout << setw(16) << "Iteration" << setw(16) << fixed <<
setprecision (8) << "PI" << endl;
for (int j = 1; j < (11 - i); j++)
for (int i = 1; i <= 2000; i += 2)
cout << " ";
{
for (int j = (11 - i); j <= 10; j++)
if (sign)
cout << "*";
pi += 4.0/i;
cout << endl;
else
pi -= 4.0/i; {

sign = !sign; for (int i = 1; i <= squareSize; i++)

cout << setw(16) << (i + 1) / 2 << setw(16) << pi << endl; {

} for (int j = 1; j <= squareSize; j++)

} cout << fillCharacter;

cout << endl;

#include <iostream>

#include <iomanip> int main()

using namespace std; {

char character;

int main() int size;

{ cout << "Vendosni madhesine e katrorit (-1 to exit): ";

double sales; cin >> size;

cout << "Vendosni vleren e sales ose shtyp -1 per te dale while (size != -1)
nga programi: ";
{
cin >> sales;
cout << "Enter fill character: ";
while (sales != -1)
cin >> character;
{
displaySquare(size, character);
cout << "rroga eshte : $" << setprecision(2) << fixed << 200
+ 0.09 * sales << endl << endl; cout << "Enter size of square (-1 to exit): ";

cout << "Vendosni vleren e sales ose shtyp -1 per te dale cin >> size;
nga programi: "; }
cin >> sales; }
}
6.22
}
#include <iostream>

using namespace std;


6.23
#include <iostream> void displaySquare(int size)
using namespace std; {

for (int i = 1; i <= size; i++)


void displaySquare(int squareSize, char fillCharacter) {
for (int j = 1; j <= size; j++) x2 = 4.0;

cout << "*"; cout << " Hipotenuza e trekëndëshit kënddrejtë me brinjë
" << x1 << " dhe " << x2 << " eshte: " <<
cout << endl;
hypotenuse(x1,x2) << endl;
}
x1 = 5.0;
}
x2 = 12.0;

cout << " Hipotenuza e trekëndëshit kënddrejtë me brinjë


int main() " << x1 << " dhe " << x2 << " eshte: " <<
{ hypotenuse(x1,x2) << endl;
int squareSize; x1 = 8.0;
cout << "Vendos madhesine e katrorit (-1 to exit): "; x2 = 15.0;
cin >> squareSize; cout << " Hipotenuza e trekëndëshit kënddrejtë me brinjë
while (squareSize != -1) " << x1 << " dhe " << x2 << " eshte: " <<

{ hypotenuse(x1,x2) << endl;

displaySquare(squareSize); }

cout << "vendos madhesine e katrorit (-1 to exit): ";

cin >> squareSize; 6.24

} #include <iostream>

} using namespace std;

6.19
int intQuotient(int number, int divisor)
#include <iostream>
{
#include <cmath>
return number / divisor;
using namespace std;
}

double hypotenuse(double side1, double side2)


int intRemainder(int number, int divisor)
{
{
return sqrt(side1 * side1 + side2 * side2);
return number % divisor;
}
}

int main()
int main()
{
{
double x1, x2;
int number;
x1 = 3.0;
int divisor = 10000;
cout << "vendos nje numer (nga 1-32767): "; for (int i = 0; i < 5; i++) {

cin >> number; if (num[i] != 7) {

while (number != 0) allSeven = false;

{ break;

if (intQuotient(number, divisor) != 0) }

{ }

cout << intQuotient(number, divisor) << " ";

number = intRemainder(number, divisor); if (allSeven) {

} for (int i = 0; i < 5; i++) {

divisor /= 10; cout << num[i] << " ";

} }

cout << endl; cout << endl;

} break;

}
ush I 2 nga ato qen a dha zysha te
shkruara }

return 0;
#include <iostream>
}
#include <cstdlib>

#include <ctime> ush I 1 nga ato qen a dha zysha te


shkruara
using namespace std; #include <iostream>

#include <cstdlib>

int main() { #include <ctime>

srand(time(0));

int num[5]; using namespace std;

bool allSeven = false;

int main() {

while (!allSeven) { srand(time(0));

for (int i = 0; i < 5; i++) { int largest = 0;

num[i] = rand() % 10; int current;

for (int i = 0; i < 10; i++) {

allSeven = true; current = rand() % 100;


cout << current << " ";

if (current > largest) {

largest = current;

cout << endl << "Numri me I madhe eshte: " << largest <<
endl;

return 0;

Ush me emrin dhe adresen


#include <iostream>

using namespace std;

void printName() {

cout << "Ami Mima" << endl;

void printAddress() {

cout << "rruga thoma kacorri" << endl;

int main() {

printName();

printAddress();

return 0;

You might also like