Friday, January 19, 2024

Find the roots of equation(x3-4x-9)Newton Raphson method.

 #include<stdio.h>

#include<math.h>

double f(double x)

{

return x*x*x-4*x-9;

}

double fd(double x)

{

return 3*x*x-4;

}

void main()

{

int i=1;

double a,b,tol;

printf("Enter value of y0:");

scanf("%lf",&a);

printf("Enter tolerance:");

scanf("%lf",&tol);

while(1)

{

       b=a;

       a=a-f(a)/fd(a);

       printf(" y%d ---> %f\n",i++,a);

       if(fabs(a-b)<tol)

           break;

}

printf("\n Solution=%f",a);

}

Output:

Enter value of y0:2

Enter tolerance:0.00001

y1 ---> 3.125000

y2 ---> 2.768530

y3 ---> 2.708196

y4 ---> 2.706529

y5 ---> 2.706528


Solution=2.706528

Enter value of y0:3

Enter tolerance:0.00001

y1 ---> 2.739130

y2 ---> 2.706998

y3 ---> 2.706528

y4 ---> 2.706528


Solution=2.706528

Enter value of y0:5

Enter tolerance:0.00001

y1 ---> 3.647887

y2 ---> 2.953279

y3 ---> 2.730187

y4 ---> 2.706777

y5 ---> 2.706528

y6 ---> 2.706528


Solution=2.706528

Simpson 3/8 Rule C Program

 #include<stdio.h>

#include<math.h>

float f(float x)

{

    return(x);

}


void main()

{

    int i,n;

    float x0,xn,h,y[20],so,se,ans,x[20];

    printf("\n Enter values of x0,xn,h: ");

    scanf("%f%f%f",&x0,&xn,&h);

    n=(xn-x0)/h;

    if(n%2==1)

    {

        n=n+1;

    }

    h=(xn-x0)/n;

    printf("\n Refined value of n and h are:%d %f\n",n,h);

    printf("\n Y values: \n");

    for(i=0; i<=n; i++)

    {

        x[i]=x0+i*h;

        y[i]=f(x[i]);

        printf("\n %f\n",y[i]);

    }

    so=0;

    se=0;

    for(i=1; i<n; i++)

    {

        if(i%3==0)

        {

            so=so+y[i];

        }

        else

        {

            se=se+y[i];

        }

    }

    printf("  i        x           y\n");

    for (i=0;i<n;i++)

    {

        printf("  %d    %lf    %lf\n",i,x[i],y[i]);

    }

    ans=h/3*(y[0]+y[n]+4*so+2*se);

    printf("\n Final integration is %f",ans);


}

trapezoidal rule numerical in c

 #include<stdio.h>

float f(float x)

{

    return(x*x);

}

void main()

{

    int i,n;

    float x0,xn,h,y[20],s=0,ans,x[20];

    printf("\n Enter values of x0,xn,h: ");

    scanf("%f%f%f",&x0,&xn,&h);

    n=(xn-x0)/h;

    if(n%2==1)

    {

        n=n+1;

    }

    h=(xn-x0)/n;

    printf("\n Refined value of n and h are:%d %f\n",n,h);

    printf("\n Y values: \n");

    for(i=0; i<=n; i++)

    {

        x[i]=x0+i*h;

        y[i]=f(x[i]);

        printf("\n %f\n",y[i]);

    }


    for(i=1; i<n; i++)

    {

            s=s+y[i];

    }


    printf("  i        x           y\n");


    for (i=0;i<n;i++)

    {

        printf("  %d    %lf    %lf\n",i,x[i],y[i]);

    }

    ans=h/2*(y[0]+y[n]+2*s);

    printf("\n Final integration is %f",ans);

}

SIMPSON'S 1/3RD RULE NUMERICAL PROGRAM IN C

 #include<stdio.h>

#include<math.h>

float f(float x)

{

    return(x);

}

void main()

{

    int i,n;

    float x0,xn,h,y[20],so,se,ans,x[20];

    printf("\n Enter values of x0,xn,h: ");

    scanf("%f%f%f",&x0,&xn,&h);

    n=(xn-x0)/h;

    if(n%2==1)

    {

        n=n+1;

    }

    h=(xn-x0)/n;

    printf("\n Refined value of n and h are:%d %f\n",n,h);

    printf("\n Y values: \n");

    for(i=0; i<=n; i++)

    {

        x[i]=x0+i*h;

        y[i]=f(x[i]);

        printf("\n %f\n",y[i]);

    }

    so=0;

    se=0;

    for(i=1; i<n; i++)

    {

        if(i%2==1)

        {

            so=so+y[i];

        }

        else

        {

            se=se+y[i];

        }


    }

    printf("  i        x           y\n");

    for (i=0;i<n;i++)

    {

        printf("  %d    %lf    %lf\n",i,x[i],y[i]);

    }

    

    ans=h/3*(y[0]+y[n]+4*so+2*se);

    printf("\n Final integration is %f",ans);


    getch();

}

Wednesday, January 10, 2024

Skill Enhancement Courses (SEC) python language

Question Set 2

1.Describe arithmetic operators in python.
2. Describe string function (any 5).
3. Describe list and its function.(any 5).
4. Compare list, tuple, dictionaries with example.
5. WAP to find all prime number between a range.
6. WAP to find an element from a list.
7. Input a word from user and count all occurrences of the word in a string.
8. Describe bitwise operators in python.
9. Explain nested if with an example in python.
10. WAP to find all armstrong number between a range.

Saturday, January 6, 2024

Os Assignment 3rd Semester General

 1. Input two numbers and print the sum.

2. Input a number an  print the factorial of a number.

3. Print fibbonacci series upto n terms.

4. Input a number and check it is even or odd.

5. Input year and check it is leap year or not.

6. Print the sum of the series 1+2+3+4+5+6...+N

7. Input a number and check it is prime or not.

8. Input a number and print the reverse of the number.

9.Input a number and check it is palindrome or not.

10. Input a string from user and the find a pattern from the user.

11. Print all file and folders under current directory.

12. Print total number of lines, characters, words in a file.