Skip to content
{{ message }}

Instantly share code, notes, and snippets.

# CanadaMike17/Partial 2

Last active May 5, 2016
TC1017 Homeworks
 #include #include using namespace std; int superpower (int a, int b){ int x, s, count=1; x=a; do { s=a*x; a=s; count++; } while(count!=b); return s; } int main () { int x,a,b,count,s; cout<< "Which is the number you want to raise: "; cin>> a; cout<< "Which is the power you want to raise it by: "; cin>> b; s=superpower(a,b); cout<< "The number: "<< a <<" raised to the exponential: "<< b << " is: "<< s < #include #include using namespace std; int main(void){ char word,ans; do{ bool palindrome=true; cout << "Please enter a word" << endl; cin>>word; int length = strlen(word); for (int i=0; i0){ for(int i=0;i<(length);i++) { if(word[i]!=word[length-1-i]) palindrome=false; } } if(palindrome==true) { cout << "The word is a palindrome" << endl; } else { cout << "The word is not a palindrome" << endl; } cout<< "do you want to repeat? "<>ans; if (ans=='n'){ break; } } while (0 != strcmp(word, "END")); return(0) ; }
 0 0 @batmantec batmantec/project.cpp Created 2 hours ago Code Revisions 1 project.cpp #include #include #include #include #include #include using namespace std; // Functions from other programs int sum(int a, int b){ int c; c=a+b; return c; } int dif (int a, int b){ int e; e=a-b; return e; } int product (int a, int b){ int f; f=a*b; return f; } int divider (int a, int b){ int g; g=a/b; return g; } int rem (int a, int b){ int h; h=a%b; return h; } //End of functions of other programs int simpleCalculator (int num1, int num2){ cout << " The sum of the two numbers is: "<< num1+num2 <=100) cout << " Water does boil at this temperature."<> menu; cout << endl; switch (menu) { case 1: int num1, num2; cout << " Please enter a integer number: "; cin >> num1; cout << " Please enter a second integer number: "; cin >> num2; simpleCalculator(num1, num2); break; case 2: int datain; cout << " Enter the temperature in Fahrenheit: "; cin >> datain; tempConverter(datain); break; case 3: int user; cout << " You have to guess the number between 1 and 100 "<> user; int random, counter; srand(time(0)); random = rand()%101; for(counter=1; user!=random; counter++){ if(user!=random){ if(user>random) cout<<" The number is to high, please try again."<>user; } } if(user==random){ cout<<" ###########################"<>low; cout<<" Please give me upper number: "; cin>>up; integerSum(low, up); break; case 5: int a, b; cout<<" Give me the first integer number: "; cin>>a; cout << endl <<" Give me the second integer number: "; cin>>b; functionCalc(a, b); break; case 6: long long int n,count,product,sum,fac; char answ; cout<<" This program calculate the factorial of a number."<> n; count=1; product=1; sum=1; if (n>1) { do{ count++; product=product*(sum+1); sum++; fac=product; }while (count!=n); cout <<" The factorial of "<> answ; } else { if (n==1) { cout << endl <<" The factorial of 1 is: 1"<>answ; } else { cout<<" The number that you enter was negative, please try again."<
 #include #include using namespace std; int superpower (int a, int b){ int x, s, count=1; x=a; do { s=a*x; a=s; count++; } while(count!=b); return s; } int main () { int x,a,b,count,s; cout<< "Which is the number you want to raise: "; cin>> a; cout<< "Which is the power you want to raise it by: "; cin>> b; s=superpower(a,b); cout<< "The number: "<< a <<" raised to the exponential: "<< b << " is: "<< s <
 #include using namespace std; void star ( int a){ int count=0; do { cout<<"*"; count++; } while (count!=a); cout<>a; star(a); return 0; }
 #include #include using namespace std; float distance (float x1, float x2, float y1, float y2) { float dis; dis=sqrt((x2-x1)*(x2-x1)+((y2-y1)*(y2-y1))); return dis; } int main () { float x1,x2,y1,y2,dis; cout<<"Hello fellows, we will now calculate the distance between 2 points in the cartesian plane"<>x1; cout<<"Lets continue to the Y number"<>y1; cout<<"Insert the second X number"<>x2; cout<<"And now the second Y number"<>y2; dis=distance(x1,x2,y1,y2); cout<<"The distance between this points is: "<< dis <
 #include using namespace std; int fib (int x) { int y; if (x>=2) { y=fib(x-1) + fib (x-2); return y; } else { if (x==1) { return 1; } else { return 0; } } } int main () { int x, ans; cout << "Give me a number: "; cin >> x; ans = fib (x); cout << "The Fibonacci number is: "<
 #include #include using namespace std; int factorial(int a) { if (a == 1 || a == 0) { return 1; } else { return a * factorial(a - 1); } } long double eulerCalc(float b) { long double a = 0.0, ans = 0.0; do { ans += 1.0/(factorial(a)); a = a + 1; } while(a <= b); return ans; } int main() { long double b, ans, a = 0.0; cout << "Please write a number: \n "; cin >> b; cout << "The answer is " << eulerCalc(b) << endl; }
 #include #include #include using namespace std; int main(void){ char word,ans; do{ bool palindrome=true; cout << "Please enter a word" << endl; cin>>word; int length = strlen(word); for (int i=0; i0){ for(int i=0;i<(length);i++) { if(word[i]!=word[length-1-i]) palindrome=false; } } if(palindrome==true) { cout << "The word is a palindrome" << endl; } else { cout << "The word is not a palindrome" << endl; } cout<< "do you want to repeat? "<>ans; if (ans=='n'){ break; } } while (0 != strcmp(word, "END")); return(0) ; }
 #include using namespace std; int array,module,i; int arrays; int find_threes(int a){ for (int i=0; i>arrays[i]; } cout<<"this numbers can be divivded by 3: "<>array; find_threes(array); return 0; }
 #include using namespace std; int dotProduct(int num1, int num2){ int ans; ans = num1*num2; return ans; } int main (){ int i, x, save = 0, sum; cout << "This program calculates the dot product." << endl; cout << "Type the number of values for each array you will be using: "; cin >> i; cout << endl; int list1[i], list2[i]; for (x = 0; x < i; x++) { cout << "Type the value " << x << " for the first array: "; cin >> list1[x]; } cout << endl; for (x = 0; x < i; x++) { cout << "Type the value " << x << " for the second array: "; cin >> list2[x]; } for (x = 0; x < i; x++) { sum = dotProduct(list1[x], list2[x]); save += sum; } cout << "The dot product is :" << save; }
 #include #include using std::cout; using std::cin; using std::endl; int getTotal(float numbers[],float numberofNumbers){ float answer=0.0; for (int i=0; i>x[i]; } sum = getTotal(x, numberofNumbers); cout<<"The addition of all the digits is: "<
 #include using namespace std; #include "BigIntegerLibrary.hh" BigInteger checkReverse(BigInteger num) { BigInteger reverse = 0; while(num != 0) { BigInteger remainder = num%10; reverse = reverse*10 + remainder; num/=10; } return reverse; } int checkNum(BigInteger num){ int ans = 0, i; BigInteger reverseNum, addition, additionReverse; reverseNum = checkReverse(num); if (num == reverseNum) { ans = 1; } else { addition = num + reverseNum; for (i = 0; i >= 30 || additionReverse != reverseNum; i++) { additionReverse = checkReverse(addition); if (additionReverse == addition) { ans = 2; break; }else{ if (i == 30) { ans = 3; break; } else { addition = addition + additionReverse; } } } } return ans; } int main (){ int low, sum, upper, lych = 0, nonLych = 0, natural = 0, i = 0, reverse, numCheck, range = 0; cout << "What is the lower bound of numbers to concider: "; cin >> low; cout << "What is the upper bound of numbers to concider: "; cin >> upper; if (low<=upper) { cout << "Continue" << endl; sum = low; for (i = low; i <= upper; i++) { range++; sum = checkNum(i); if (sum == 1) { natural++; } else { if (sum == 2) { nonLych++; } else { if (sum == 3) { lych++; } else { cout << "There was an error in the code" << endl; } } } } cout << "The range of numbers analysed is: " << range << endl; cout << "The number of natural palindromes is: " << natural << endl; cout << "The number of non-Lycherels encountered is: " << nonLych << endl; cout << "The number of Lycherel number candidates is: " << lych << endl; }else { cout << "The lower number was higher than the upper number, please try again."; } }
 #include #include #include using namespace std; int CheckFile(string fileName){ ifstream InList; InList.open(fileName.c_str()); if (InList.is_open()) { cout << "File Open" << endl; cout << endl; return 1; } else { return 0; } } int ReadFile(string word, string fname){ int counter; string foundWord; ifstream InList; InList.open(fname.c_str()); while (!InList.eof()) { InList >> foundWord; if (foundWord == word) { counter++; } } InList.close(); return counter; } int main(){ string word, fname; cout <<"Enter the File name with .txt at the end:" << endl; cin >> fname; if (CheckFile(fname)==0) { cout << "Please check the File name and location." << endl; } cout <<"Enter the word to search: " << endl; cin >> word; cout << endl << "The word " << '"' << word << '"' <<" was found " << ReadFile(word, fname) << " time(s) in the File." << endl; }
 #include using namespace std; int main () { cout <<"Hello World"<< endl; return 0; }
 #include using namespace std; int main (){ int num1, num2; cout << "Insert a integer number: " ; cin >> num1 ; cout << "Insert another integer number: " ; cin >> num2 ; cout << "If you add them the result is: " << num1+num2 <
 #include using namespace std; int main (){ int temperature,celsius; cout << "Please introduce the Farenheit temperature you'd like to know: " ; cin >> temperature ; celsius = (5*(temperature-32)/9); cout << "The temperature in Celsius is: "<=100) cout << "Water does boil at this temperature" <
 #include #include #include using namespace std; int main (){ int num, random, cont; srand(time(0)); random = rand()%101; cout << "You will be asked to select a number between 1-100 " << endl; cout << "Good Luck" <> num; for (cont=1; num!= random; cont++) { if (num!=random) { if(numrandom) cout << "Your number is bigger than mine...HAHAHAHA" <>num; } } if (num==random) { cout << "Lucky you, you finally did it" <
 #include using namespace std; int main (){ int low, high, sum; sum =0; cout<< "insert a lower bound" << endl; cin >> low cout<< "insert a higher bound"<> high if (low<=high) { do { low = low++; sum = sum+low; }while (low!=high); cout << "The sum of the numbers is: " << sum << endl;} else { cout << "the numbers are incorrect" << endl; } return 0; }
 #include using namespace std; int add (int a, int b) { int s; s=a+b; return s; } int substraction (int a, int b) { int r; r=a-b; return r; } int mult (int a, int b) { int m; m=a*b; return m; } int div (int a, int b) { int d; d=a/b; return d; } int intdiv (int a, int b) { int i; i=a%b; return i; } int main () { int a, b, s, r, m, d, i; cout<< "Give me a integer number" << endl; cin>>a; cout<< "Give me a second integer number" << endl; cin>>b; s=add (a,b); r=substraction (a,b); m=mult (a,b); d=div (a,b); i=intdiv (a,b); cout << "The addition of the numbers is: "<
 #include using namespace std; int main() { int num,factorial=1; cout<<" Enter Number To Find Its Factorial: "; cin>>num; for(int a=1;a<=num;a++) { factorial=factorial*a; } cout<<"Factorial of Given Number is ="<
to join this conversation on GitHub. Already have an account? Sign in to comment