By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,294 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Need a program that can answer the following problems

P: 6
1. The program should be able to solve the following problems
a. decision to be made if a given number is a prime
b. Fibonacci number calculation (F1=1, F2=1, Fn=Fn-2+Fn-1)
c. determinant computation (of order 1 and order 2, extra credit: order 3)
d. matrix addition (should work 2x2, 2x3 and 3x3 matrices, e. matrix multiplication (at least 1xm and mx1 matrices

It should be done in C++ formatting
Nov 1 '06 #1
Share this Question
Share on Google+
5 Replies


Ganon11
Expert 2.5K+
P: 3,652
So what have you been able to figure out so far?
Nov 1 '06 #2

P: 6
So what have you been able to figure out so far?
Nothing really becuase this is only my 3rd time doing programming. The first two were just using couts and cins like ansering questions for a program. Im not sure how to use numbers. I tried this program for part a which is decison to be made if a given number is prime.

#include <iostream>

using namespace std;

int isprime(int Prime_Number);
int main()
{
int Number = 0;
cout<<"Enter a number"<<endl;
cin>>Number;
if(Number>0)
{
if(isprime(Number)==0)
{
cout<<"Number is prime"<<endl;
}
else
{
cout<<"Number is not prime"<<endl;
}
}
else
{
cout<<"Positive numbers only"<<endl;
}
return 0;
}


int isprime(int Prime_Number)
{
//prime number calculation here
}
Nov 1 '06 #3

100+
P: 1,646
Nothing really becuase this is only my 3rd time doing programming. The first two were just using couts and cins like ansering questions for a program. Im not sure how to use numbers. I tried this program for part a which is decison to be made if a given number is prime.

#include <iostream>

using namespace std;

int isprime(int Prime_Number);
int main()
{
int Number = 0;
cout<<"Enter a number"<<endl;
cin>>Number;
if(Number>0)
{
if(isprime(Number)==0)
{
cout<<"Number is prime"<<endl;
}
else
{
cout<<"Number is not prime"<<endl;
}
}
else
{
cout<<"Positive numbers only"<<endl;
}
return 0;
}


int isprime(int Prime_Number)
{
//prime number calculation here
}
As a clue: you should be checking out the Mod operator
Nov 1 '06 #4

Banfa
Expert Mod 5K+
P: 8,916
You need to know what algorithm to use to find before you worry about putting it into code.

For instance I assume you know what a prime number is? So on paper how would you answer the question "Is 221 a prime number?"?

Can you make the computer do the same thing for any number?
Nov 1 '06 #5

P: 6
You need to know what algorithm to use to find before you worry about putting it into code.

For instance I assume you know what a prime number is? So on paper how would you answer the question "Is 221 a prime number?"?

Can you make the computer do the same thing for any number?

I run the program and it says this

Warning W8070 roach5.cpp 33: Function should return a value in function isprime(
int)
Warning W8057 roach5.cpp 33: Parameter 'Prime_Number' is never used in function
isprime(int)
Nov 12 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.