Posts

Showing posts from November, 2014

C++ | Using Simpsons Rule to Numerically integrate an equation !

Image
So here is the code and the explanation below : #include <iostream> #include <cmath> using namespace std; main(){ int a,b,n; cout << "Enter upper limit, b:"; cin >> b; cout << "Enter lower limit, a:"; cin >> a; cout << "\nEnter number of Simpson's interval, n (even number only):"; cin >> n; long double dx, t=0; dx = (long double)(b-a)/n; long double fx[n+1]; for(int i=0;i<=n;i++){ if (i == 0){ t = a; } else if (i == n){ t = b; } else{ t = a+(i*dx); } //cout << "t = " << t << endl; // im just curious to know fx[i] = (1.36*pow(10,-10))*t*t*t*t - (1.23*pow(10,-7))*t*t*t + (4.12*pow(10,-6))*t*t + (3.95*pow(10,-4))*t - (8.58*pow(10,-2)); //fx[i] = (double)1 / (t + 1 ); //cout << "fx[" << i << "] =

C++ | Program That can Add, subtract, multiply and divide fraction and give answer in simplest form !

Image
So here is the code and the explanation below : #include <iostream> using namespace std; void fractions(int x, int y,int w, int z); void addi(int x, int y,int w, int z); void subt(int x, int y,int w, int z); void multiply(int x, int y,int w, int z); void division(int x, int y,int w, int z); main (){ int num1, den1, num2, den2,dec; cout << "Enter Numerator 1:" ; cin >> num1; cout << "\nEnter Denominator 1:" ; cin >> den1; cout << "\nEnter Numerator 2:" ; cin >> num2; cout << "\nEnter Denominator 2:" ; cin >> den2; fractions(num1, den1, num2, den2); cout << "\nEnter 1 for Addition"; cout << "\nEnter 2 for Subtraction"; cout << "\nEnter 3 for Multiplication"; cout << "\nEnter 4 for Division"; cout << "\nWhat operation you want to do:"; cin >> d

C++ | Program That Accept 6-digits integer and then print back in reverse order

Image
So here is the code and the explanation below : #include <iostream> using namespace std; // else you need to code like this std::cout << "blablah"; int main() { int n, d; int i = 0, total=0; cout << "Enter number:"; cin >> n; cout << "\nThe reverse number is : " << endl; while (i <= 5) { d = n%10; // n remainder 10 total = total + d; cout << d << endl; // print out remainder n = n/10; // integer divide by 10 i++; } cout << "\nThe sum of the six digits is = " << total << endl ; return 0; } This program simply accept 6 digits number. ( well you can actually modify it for more ) But for the purpose to finish up my assignment, I keep it simple.  The 6 digits integer is stored in integer n which is actually a single integer (etc: 12456). And then it will enter the reversal loop, (the while loo