anyway ive been working on 2 different programs in that time
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int num;
int x;
int root;
bool prime;
cout << "Please enter a number: ";
cin >> num;
cout << endl;
root = pow(num, 0.5);
for (x=2; x <= root; x++)
{
if (num % x == 0)
{
cout << "number is not prime" << endl;
prime = false;
}
else
{
cout << "number is prime" << endl;
prime = true;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
for this one you are input a positive number and the output is supposed to tell you if the number you input is a prime number(if you cant tell this week is loops)
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
int counter;
int num;
int zero = 0;
int even = 0;
int odd = 0;
int N = 10;
int sum = 0;
cout << "please enter " << N << " integers, "
<< "posative, negative, or zeros."
<< endl;
cout << "the numbers you entered are:" << endl;
for (counter = 1; counter <=N; counter++)
{
cin >> num;
cout << num << " ";
switch (num % 2)
{
case 0:
even++;
if (num == 0)
zero++;
while (num == even)
{
sum = sum + num;
cin >> num;
}
break;
case 1:
case -1:
odd++;
}
}
cout << endl;
cout << "there are " << even << " evens, "
<< "which includes " << zero << " zeros. "
<< endl;
cout << "the number of odd numbers is: " << odd
<< endl;
system("PAUSE");
return EXIT_SUCCESS;
}
this one was tough, you have to enter a set of numbers and then have it output the sum of the even numbers and odd numbers and how many zeros there are
No comments:
Post a Comment