0% found this document useful (0 votes)
12 views2 pages

assigment 2

Uploaded by

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

assigment 2

Uploaded by

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

Dardan Zhaku ID number:132494

1
#include <iostream>
using namespace std;

int swap(int n)
{
int l = n % 10; // last is for left
int f = n; //f is for first i wrote these as a comments so its not
confusing
while (f >= 10)
{
f /= 10;
}

int temp = n / 10;


temp = temp / 10;

n = l * 10;
while (temp > 0)
{
n = n * 10 + temp % 10;
temp /= 10;
}
n = n * 10 + f;

return n;
}

int main()
{
int n;
cout << "Enter a number: ";
cin >> n;

cout << "After swapping the first and last digits: " << swap(n) << endl;
return 0;
}
2
#include <iostream>
using namespace std;

int main()
{
int num, tcount = 0, sum = 0;

cout << "Enter numbers" << endl;

while (true)
{
cin >> num;

if (num == 0)
{
break;
}
tcount++;

if (num > 0 && num % 2 == 0)


{
sum += num;
}
}

cout << "Total " << tcount << endl;


cout << "Sum " << sum << endl;

return 0;
}
3
#include <iostream>
using namespace std;

int main()
{
int n;
double pi = 0.0;
int i = 0;

cout << "Enter the number of terms: ";


cin >> n;

while (i < n)
{
double term = 1.0 / (2 * i + 1);
if (i % 2 == 0)
{
pi += term;
}
else
{
pi -= term;
}
i++;
}

pi *= 4;

cout << "number of terms " << n << " result " << pi << endl;

return 0;
}

You might also like