https://www.youtube.com/watch?v=6kScLENCXLg
https://www.mathsisfun.com/calculus/implicit-differentiation.html
https://www.mathway.com/popular-problems/Algebra/200043
https://www.youtube.com/watch?v=6kScLENCXLg
https://www.mathsisfun.com/calculus/implicit-differentiation.html
https://www.mathway.com/popular-problems/Algebra/200043
Posted in Mathematics
for formula: http://www.mathsisfun.com/area.htm
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> double pi=3.1416; double britto(double r) { double area=pi*r*r; return area; } int main() { double r=3; double khetrofol=britto(r); printf("%lf",khetrofol); return 0; } |
We have to always remember that value that define is always pass from main function to customized function named by user so here r=3 is passing to function britto and then the britto formula pi*r*r is applying and returned the value and it is printed in the main function where the variable defined as khetrofol.
Here pi declared as global variable with it’s value.
Did this problem from subeen vai’s book.
For maximum value:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int find_max(int ara[],int n); int main() { int ara[]={-100,0,53,22,83,23,89,-132,201,3,85}; int n=11; int max=find_max(ara,n); printf("%d\n",max); return 0; } int find_max(int ara[],int n) { int max=ara[0]; //assume that first value of array according to index is maximum we will compare later with this int i; for(i=1;i<n;i++) { if(ara[i]>max) //here it is iterating the whole array { max=ara[i]; } } return max; } |
For minimum value:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int find_min(int array[],int n); int main() { int array[]= {20,10,-123,980,60,50,70}; int n=7; int min; min=find_min(array,n); printf("%d\n",min); return 0; } int find_min(int array[],int n) { int min=array[0]; int i; for(i=0; i<n; i++) { if(array[i]<min) { min=array[i]; } } return min; } |
Summation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> int find_sum(int ary[],int valu); int main() { int ary[]={10,20,30}; int n=3; int sum; sum=find_sum(ary,n); printf("%d\n",sum); return 0; } int find_sum(int ary[],int n) { int i; int sum=0; for(i=0;i<n;i++) { sum=sum+ary[i]; } return sum; } |
Average:
Will give here
Posted in A ll Codes, ACM-ICPC, Array, Mathematics
http://www.prothom-alo.com/bangladesh/article/580627/%E0%A6%97%E0%A6%A3%E0%A6%BF%E0%A6%A4-%E0%A6%85%E0%A6%B2%E0%A6%BF%E0%A6%AE%E0%A7%8D%E0%A6%AA%E0%A6%BF%E0%A7%9F%E0%A6%BE%E0%A6%A1%E0%A7%87%E0%A6%B0-%E0%A6%A4%E0%A6%BE%E0%A6%B0%E0%A6%95%E0%A6%BE%E0%A6%B0%E0%A6%BE-%E0%A6%95%E0%A7%87-%E0%A6%95%E0%A7%8B%E0%A6%A5%E0%A6%BE%E0%A7%9F
Multiple of 3 is
3×1=3
3×2=6
3×3=9
3×4=12
3×5=15
3×6=18
3×7=21
3×8=24
3×9=27
3×10=30
Multiple of 4 is
4×1=4
4×2=8
4×3=12
4×4=16
4×5=20
4×6=24
4×7=28
4×8=32
4×9=36
4×10=40
Here in 3 and 4 mutilples common is 12
and it is only one value and so it is the lowest also then but if there were some more values than result could be something changed.
So here LCM=12
Here I implemented the code
applied this formula
lcm(a,b)=a*b/gcd(a,b);
code goes here :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include<stdio.h> int main() { int a,b,x,gcd,lcm; scanf("%d %d",&a,&b); if(a<b)//it is not possible for gcd to be greater than the lowest value { x=a; } else { x=b; } for( ;x>=1;x--){ //here i haven't initialized the value of x as x is first at outside if(a%x==0 && b%x==0){ gcd=x; break; //here i have used break as if it is not here then when the division will happen it will run the loop till 1 so answer will be always 1 } } printf("GCD is %d\n",gcd); lcm=a*b/gcd; printf("LCM is %d\n",lcm); return 0; } |
এখানে লজিকটা হচ্ছে…Here the logic is:
For 12:
1×12=12
2×6=12
3×4=12
So factor of 12=1,2,3,4,6,12
(We don’t need the negative values here)
For 30:
1×30=30
2×15=30
3×10=30
5×6=30
So factor of 30=1,2,3,5,6,10,15,30
Now which is the common factor among 12 and 30
So factor of 12=1,2,3,4,6,12
So factor of 30=1,2,3,5,6,10,15,30
common factor=1,2,3,6
Largest common factor here=6
So now if we divide 12/6 then we get 2
and for 30/6 we get 5
that is all divided perfectly so the logic should be like this
1.Find all the factors of each number
2. Circle the common factors
3. Choose the greatest of those
4. Divide the existing number with greatest common factor thern also get a perfect divide
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<stdio.h> int main() { int a,b,x,gcd; scanf("%d %d",&a,&b); if(a<b)//it is not possible for gcd to be greater than the lowest value { x=a; } else { x=b; } for( ;x>=1;x--){ //here i haven't initialized the value of x as x is first at outside if(a%x==0 && b%x==0){ gcd=x; break; //here i have used break as if it is not here then when the division will happen it will run the loop till 1 so answer will be always 1 } } printf("GCD is %d\n",gcd); return 0; } |
Here is a link that described many thinks about this clearly: http://www.mathsisfun.com/greatest-common-factor.html
Another method can also apply here:
link for understanding the modarithmetic euclidean algorithmhttps://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/the-euclidean-algorithm
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int main() { int a,b,t,x,gcd; scanf("%d %d",&a,&b); if(a==0) gcd=a; else if(b==0) gcd=b; else { while(b!=0) { t=b; b=a%b; a=t; } gcd=a; } printf("GCD is %d\n",gcd); return 0; } |
An equation ax2 + bx + c = 0 where a,b and c are any number and called the coefficient of the equation
It is known as quadratic equation because any seconbd degree polynomial equation is known as quadratic equation.This equation has two roots x1 and x2
This is Bhaskara’s Formula or Bhaskaracharya’s Formula where discriminant D or Del = b2 − 4ac
If D>0 then root of quadratic equation are real and unequal
If D=0 then root of quadratic equation are real and equal
If D<0 then root of quadratic equation are conjugate complex number
Source:http://encyclopedia2.thefreedictionary.com/Bhaskaracharya%2
7s+Formula
http://www.wolframalpha.com/input/?i=Bhaskara%20formula
So my code is here
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<iostream> #include<cstdio> #include<cmath> int main() { double a,b,c,r1,r2,d; scanf("%lf %lf %lf",&a,&b,&c); d=(pow(b,2)-(4*a*c)); r1=(-b+sqrt(d))/(2*a); r2=(-b-sqrt(d))/(2*a); if(a!=0 && d>0) { printf("R1 = %.5lf\nR2 = %.5lf\n",r1,r2); } else{ printf("Impossivel calcular\n"); } return 0; } |
Posted in A ll Codes, Mathematics, Problem Solution, Programming, URI Online Judge
Tagged uri, urionlinejudge
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include<stdio.h> #include<math.h> #include<stdlib.h> main() { float x[20],y[20],f,s,h,d,p; int j,i,n; printf("enter the value of n :"); scanf("%d",&n); printf("enter the elements of x:"); for(i=1;i<=n;i++) { scanf("\n%f",&x[i]); } printf("enter the elements of y:"); for(i=1;i<=n;i++) { scanf("\n%f",&y[i]); } h=x[2]-x[1]; printf("Enter the value of f(to findout value):"); scanf("%f",&f); s=(f-x[1])/h; p=1; d=y[1]; for(i=1;i<=(n-1);i++) { for(j=1;j<=(n-i);j++) { y[j]=y[j+1]-y[j]; } p=p*(s-i+1)/i; d=d+p*y[1]; } printf("For the value of x=%6.5f THe value is %6.5f",f,d); getch(); } |
Output:
Posted in A ll Codes, Mathematics, Numerical Method
Tagged newton forward interpolation
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include<stdio.h> #include<math.h> int main() { float x[10],y[10],temp=1,f[10],sum,p; int i,n,j,k=0,c; printf("\nhow many record you will be enter: "); scanf("%d",&n); for(i=0; i<n; i++) { printf("\n\nenter the value of x%d: ",i); scanf("%f",&x[i]); printf("\n\nenter the value of f(x%d): ",i); scanf("%f",&y[i]); } printf("\n\nEnter X for finding f(x): "); scanf("%f",&p); for(i=0;i<n;i++) { temp = 1; k = i; for(j=0;j<n;j++) { if(k==j) { continue; } else { temp = temp * ((p-x[j])/(x[k]-x[j])); } } f[i]=y[i]*temp; } for(i=0;i<n;i++) { sum = sum + f[i]; } printf("\n\n f(%.1f) = %f ",p,sum); getch(); } |
Output:
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include<stdio.h> #include<math.h> int main() { float x[10],y[10],temp=1,f[10],sum,p; int i,n,j,k=0,c; printf("\nhow many record you will be enter: "); scanf("%d",&n); for(i=0; i<n; i++) { printf("\n\nenter the value of x%d: ",i); scanf("%f",&x[i]); printf("\n\nenter the value of f(x%d): ",i); scanf("%f",&y[i]); } printf("\n\nEnter X for finding f(x): "); scanf("%f",&p); for(i=0;i<n;i++) { temp = 1; k = i; for(j=0;j<n;j++) { if(k==j) { continue; } else { temp = temp * ((p-x[j])/(x[k]-x[j])); } } f[i]=y[i]*temp; } for(i=0;i<n;i++) { sum = sum + f[i]; } printf("\n\n f(%.1f) = %f ",p,sum); getch(); } |
Output:
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include<stdio.h> #include<math.h> int main() { float x[10],y[10],temp=1,f[10],sum,p; int i,n,j,k=0,c; printf("\nhow many record you will be enter: "); scanf("%d",&n); for(i=0; i<n; i++) { printf("\n\nenter the value of x%d: ",i); scanf("%f",&x[i]); printf("\n\nenter the value of f(x%d): ",i); scanf("%f",&y[i]); } printf("\n\nEnter X for finding f(x): "); scanf("%f",&p); for(i=0;i<n;i++) { temp = 1; k = i; for(j=0;j<n;j++) { if(k==j) { continue; } else { temp = temp * ((p-x[j])/(x[k]-x[j])); } } f[i]=y[i]*temp; } for(i=0;i<n;i++) { sum = sum + f[i]; } printf("\n\n f(%.1f) = %f ",p,sum); getch(); } |
Output:
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include<stdio.h> #include<math.h> int main() { float x[10],y[10],temp=1,f[10],sum,p; int i,n,j,k=0,c; printf("\nhow many record you will be enter: "); scanf("%d",&n); for(i=0; i<n; i++) { printf("\n\nenter the value of x%d: ",i); scanf("%f",&x[i]); printf("\n\nenter the value of f(x%d): ",i); scanf("%f",&y[i]); } printf("\n\nEnter X for finding f(x): "); scanf("%f",&p); for(i=0;i<n;i++) { temp = 1; k = i; for(j=0;j<n;j++) { if(k==j) { continue; } else { temp = temp * ((p-x[j])/(x[k]-x[j])); } } f[i]=y[i]*temp; } for(i=0;i<n;i++) { sum = sum + f[i]; } printf("\n\n f(%.1f) = %f ",p,sum); getch(); } |
Output:
Problem: The population of a town is given below as thousands
Year : 1891 1901 1911 1921 1931
Population : 46 66 81 93 101
Find the population of 1895 ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include<stdio.h> #include<math.h> #include<stdlib.h> main() { float x[20],y[20],f,s,d,h,p; int j,i,k,n; printf("enter the value of the elements :"); scanf("%d",&n); printf("enter the value of x:\n"); for(i=1;i<=n;i++) { scanf("%f",&x[i]); } printf("enter the value of y:\n"); for(i=1;i<=n;i++) { scanf("%f",&y[i]); } h=x[2]-x[1]; printf("enter the searching point f:"); scanf("%f",&f); s=(f-x[n])/h; d=y[n]; p=1; for(i=n,k=1;i>=1,k<n;i--,k++) { for(j=n;j>=1;j--) { y[j]=y[j]-y[j-1]; } p=p*(s+k-1)/k; d=d+p*y[n]; } printf("for f=%f ,ans is=%f",f,d); getch(); } |
Output:
Posted in A ll Codes, Mathematics, Numerical Method
Problem: Solve the following systems using gauss seidel method
5×1-x2-x3-x4=-4
-x1+10×2-x3-x4=12
-x1-x2+5×3-x4=8
-x1-x2-x3+10×4=34
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include<stdio.h> #include<conio.h> #include<math.h> #define acc 0.0001 #define X1(x2,x3,x4) ((x2 + x3 + x4 -4)/5) #define X2(x1,x3,x4) ((x1 + x3 + x4 +12)/10) #define X3(x1,x2,x4) ((x1 + x2 + x4 +8)/5) #define X4(x1,x2,x3) ((x1 + x2 + x3 +34)/10) void main() { double x1=0,x2=0,x3=0,x4=0,y1,y2,y3,y4; int i=0; system("cls"); printf("\n______________________________________________________________\n"); printf("\n x1\t\t x2\t\t x3\t\t x4\n"); printf("\n______________________________________________________________\n"); printf("\n%f\t%f\t%f\t%f",x1,x2,x3,x4); do { y1=X1(x2,x3,x4); y2=X2(x1,x3,x4); y3=X3(x1,x2,x4); y4=X4(x1,x2,x3); if(fabs(y1-x1)<acc && fabs(y2-x2)<acc && fabs(y3-x3)<acc &&fabs(y4-x4) ) { printf("\n_____________________________________________________________\n"); printf("\n\nx1 = %.3lf",y1); printf("\n\nx2 = %.3lf",y2); printf("\n\nx3 = %.3lf",y3); printf("\n\nx4= %.3lf",y4); i = 1; } else { x1 = y1; x2 = y2; x3 = y3; x4 = y4; printf("\n%f\t%f\t%f\t%f",x1,x2,x3,x4); } }while(i != 1); getch(); } |
Output: