#include<iostream> using namespace std; template<typename T> T* addArray(T* array, int size); template<typename T> T primeNumber(T number); template<typename T> T Factorial(T number); int main() { int IntNum, Size; float FloatNum; cout << "Enter an integer " << endl; cin >> IntNum; cout << "Enter a float number " << endl; cin >> FloatNum; cout << "Enter size of the array " << endl; cin >> Size; int* Array = new int[Size]; cout << "Enter elements of the array " << endl; for (int i = 0; i < Size; i++) cin >> Array[i]; addArray<>(Array, Size); if (primeNumber<int>(IntNum) == true); cout << IntNum << " is a prime number " << endl; if(primeNumber<int>(IntNum) == false) cout << IntNum << " is not a prime number " << endl; cout<<"Factorial of the "<<IntNum<<" is "<<Factorial<int>(IntNum); return 0; } template<typename T> T primeNumber(T number) { bool flag = false; for (int i = 2; i < number; i++) if (number % i == 0) return flag; flag = true; return true; } template<typename T> T Factorial(T number) { if (number >=1) return number * Factorial(number - 1); else { return 1; } } template<typename T> T* addArray(T* array, int size) { T* newarray = new int[size]; for (int i = 0; i < size; i++) newarray[i] = array[i] + array[i]; return newarray; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter