0% found this document useful (0 votes)
2 views

Lab 6

Uploaded by

manas.sep20
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)
2 views

Lab 6

Uploaded by

manas.sep20
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/ 7

Task 1:

Code:

#include<iostream>
using namespace std;
int main()
{
float n, sum = 0, ave = 0, min = 0, count = 1.0;
bool zeroflag = 1;
while (zeroflag)
{
cout << "Enter vlaues for sum, average and comparison,
or enter 0 to terminate: ";
cin >> n;
{
{
if (count == 1)
min = n;
}
{
if (n == 0)
zeroflag = 0;
else
{
sum = (float)sum + n;
ave = (float)sum / count;
count++;
{
if (min > n)
min = n;
}

}
}
}
cout << "sum is " << sum << endl;
cout << "average is " << ave << endl;
cout << "min number is " << min << endl;
}

Output:

Task 2:
Code:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
int a, r, n, i = 1;
cout << "Enter first term: ";
cin >> a;
cout << "Enter common ratio: ";
cin >> r;
cout << "Enter number of series integers: ";
cin >> n;
while (i <= n)
{
cout << setw(8) << left<<a;
a = a * r;
i++;

Output:

Task 3:
Code:
#include<iostream>
using namespace std;
int main()
{
int n;
cout << "Enter the number between 1 and 10: ";
cin >> n;
while (n <= 1 || n >= 10)
{
cout << "Re-enter the number between 1 and 10: ";
cin >> n;
}
cout << "Number entered is " << n;
}

Output:

Task 4:
Code:
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
int a=0,b=1,terms,i=1;
cout << "Enter the number of terms: ";
cin >> terms;
while (i <= terms/2)
{
cout << setw(8) << left << a;
cout << setw(8) << left << b;
a = a + b;
b = a+b;
i++;
}
if(terms%2!=0)
cout << setw(8) << left << b;

Output:

Task 5:
Code:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n, i = 1;
cout << "Enter a number: ";
cin >> n;
cout << "Positive divisors are: " << endl;
if (n < 0)
{
n = n * -1;
}
while (i <= n)
{
if (n % i == 0)
{
cout << i << endl;
}
i = i + 1;
}
}

Output:

Task 6:
Code:
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a, b,max,min,i=2;
cout << "Enter first value: ";
cin >> a;
cout << "Enter second value: ";
cin >> b;
a > b? max = a : max = b;
a > b ? min = b : min = a;
while (i <= max)
{
{
if (i > min)
cout << i << endl;
}
i = i + 2;
}

Output:

You might also like