Posts

C Program To Calculate Values Using Fixed Point Iteration and Honors Method | C Programming

C Program To Calculate Values Using Fixed Point Iteration Method Algorithm Start Read values of x0 and e. *Here x0 is the initial approximation e is the absolute error or the desired degree of accuracy, also the stopping criteria* Calculate x1 = g(x0) If [x1 – x0] <= e, goto step 6. *Here [ ] refers to the modulus sign* Else, assign x0 = x1 and goto step 3. Display x1 as the root. Stop #include<stdio.h> #include<math.h> #include<conio.h> #define EST 0.05 #define F(x) exp(-x)-x #define G(x) exp(-x) int main() { int i=1; float error,x0,x1,temp; printf("Enter the initial guess x0:\n"); scanf("%f",&x0); printf("Iteration x0\t\t x1\t Error\n"); x1=G(x0); error=fabs((x1-x0)/x1); printf("%d\t %.4f\t%.4f\t %.4f\n",i,x0,x1,error); do { i++; temp=x1; x0=temp; x1=G(x0); error=fabs((x1-x0)/x1); printf("%d\t %.4f\t%.4f\t %.4f\n",i,x0,x1,error); }while (error>EST); } C Program To Calculate Values Using Ho

C program to find value using Bisection Method | C Programming

C program to find value using Bisection Method | C Programming #include<stdio.h> #include<conio.h> #include<math.h> #define EST 0.05 #define F(x) pow(x,3)-x-3 int main() { int i=1; float xl,xu,xm,f1,f2,f3,error; printf("Enter the values for xl and xu respectively\n"); scanf("%f%f",&xl,&xu); printf("Iteration\tXl\t Xu\t f(Xm)\t Error\n"); do { xm=(xl+xu)/2; f1=F(xl); f2=F(xu); f3=F(xm); error=fabs((xl-xu)/xu); if((f1*f3)<0) { xu=xm; } else { xl=xm; } f3=F(xm); error=fabs((xl-xu)/xu); printf("%d\t %.4f\t %.4f\t%.4f\t %.4f\n",i,xl,xu,xm,error); i++; }while (error>=EST); }

C program to find value using secant method | C programming

C program to find value using secant method | C programming #include<stdio.h> #include <math.h> #include<conio.h> #define EST 0.05 #define F(x) x-exp(x)+2 int main() { int i = 1; float x0,x1,a,b,c,d,f1,x2,f0,error; printf("\nEnter the value of x0: "); scanf("%f",&x0); printf("\nEnter the value of x1: "); scanf("%f",&x1); printf("\n__________________________________________________________________\n"); printf("\niteration\tx0\t x1\t f0\t f1\t x2\t\terror"); printf("\n___________________________________________________________________\n"); f0=F(x0); f1=F(x1); x2=x1-((f1*(x1-x0))/(f1-f0)); printf("%f",x2); error=fabs((x2-x1)/x2); printf("\n %d \t %.2f\t %.2f\t %.2f \t %.3f \t %.3f \t %.3f", i, x0,x1,f0,f1,x2,error); do{ i++; x0=x1; f0= f1; x1=x2; f0=F(x0); f1=F(x1); x2=x1-((f1*(x1-x0))/(f1-f0)); error=fabs((x2-x1)/x2); printf("\n %d \t %.2f\t %.2f\t %.2f \t %.4f \

C program to find the value using Newton Raphson | C Programming

C program to find the value using Newton Raphson Before starting with the program let us learn something about Newton Raphson Method Newton Raphson Method  is open method and starts with one initial guess for finding real root of non-linear equations. In other Words,  Newton Raphson method, also called the Newton’s method, is the fastest and simplest approach of all methods to find the real root of a nonlinear function. It is an open bracket approach, requiring only one initial guess. This method is quite often used to improve the results obtained from other iterative approaches

C program to calculate Chinese remainder theorem | C Programming

C program to calculate the Chinese remainder theorem  #include <stdio.h> int main () {     int user_num [ 2 ];     int numbers [ 4 ];     int a [ 10 ][ 10 ];     int i , j , sum [ 4 ];     printf ( " \n Enter two numbers of seven digits: \n " );     for ( i = 0 ; i <= 1 ; i ++)     {         scanf ( " %d " , & user_num [ i ]);     }     printf ( " \n\n Enter four relative prime numbers: \n " );     for ( i = 0 ; i < 4 ; i ++)     {         scanf ( " %d " , & numbers [ i ]);     }     for ( i = 0 ; i < 2 ; i ++)     {         for ( j = 0 ; j < 4 ; j ++)         {             a [ i ][ j ] = user_num [ i ] % numbers [ j ];         }     }     for ( i = 0 ; i < 4 ; i ++)     {         j = 0 ;         sum [ i ] = ( a [ j ][ i ] + a [ j + 1 ][ i ]) % numbers [ i ];     }     printf ( " \n\n The tuple of 4 numbers is: \n\n " );     printf ( "(" );     for ( i = 0 ; i < 4

C Program To Generate Permutation And Combination | C Programming

C Program To Generate Permutation #include <stdio.h> long int fact ( int x ) {     long int f = 1 ;     int i ;     for ( i = 1 ; i <= x ; i ++)         f = f * i ;     return ( f ); } int main () {     int n , r , i , p ;     printf ( "Enter value of n and r : " );     scanf ( " %d %d " , & n , & r );     if ( n >= r )     {         p = fact ( n ) / fact ( n - r );         printf ( "Permutation P( %d , %d ) = %d " , n , r , p );     }     else     {         printf ( "Wrong Input ! Enter n>=1 ." );     }     return 0 ; } C Programming To Generate Combination | C Programming #include <stdio.h> long int fact ( int x ) {     long int f = 1 ;     int i ;     for ( i = 1 ; i <= x ; i ++)         f = f * i ;     return ( f ); } int main () {     int n , r , i , ncr ;     printf ( "Enter value of n and r : " );     scanf ( " %d %d " , & n , & r );

C++ Program To Find implication | C++ Programming

Implication:- The statement “p implies q” means that if p is true, then q must also be true. The statement “p implies q” is also written “if p then q” or sometimes “q if p.” Statement p is called the premise of the implication and q is called the conclusion.