Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Functions in c

  1. Jun 24, 2009 #1
    can somebody help me on writting a program that displays yo
    to yn+1 when n=100 and store them in a file.
    y"=cos(t)*y+y
    y(0)=1
    y'(0)=0
    h=0.1
    y'=z
    z'=z'*cos(t)+y
    yn+1=zn+h*zn*(cos(tn))+yn)
    tn=t+nh
     
  2. jcsd
  3. Jun 24, 2009 #2
    i have the above using for loop without declaring any fuction,
    if someone knows how to solve it including user defined function then he might be able to help me.
    thank you!
    the one i wrote is showed below

    #include<stdio.h>
    #include<math.h>
    #include<stdlib.h>
    main()
    {
    FILE *fp;
    fp=fopen("D:\\cop.txt","w");
    float y[100],dy[100],z[100],h,t[100];
    int i;
    y[0]=1;
    z[0]=0;
    h=0.1;
    t[0]=0;
    for(i=0;i<100;i++)
    {
    t=t[0]*i*h;
    y[i+1]=y+h*z;
    z[i+1]=z+h*((z*cos (t))+y);
    }
    fprintf(fp,"i\tz(n+1)\t\ty(n+1)\n\n");
    printf("i\tz(n+1)\t\ty(n+1)\n\n");
    for(i=0;i<100;i++)
    {

    fprintf(fp,"%d\t%f\t%f\n",i,z[i+1],y[i+1]);
    printf("%d\t%f\t%f\n",i,z[i+1],y[i+1]);
    }
    fclose(fp);
    system("PAUSE");

    }
     
    Last edited: Jun 24, 2009
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Functions in c
  1. C++ function (Replies: 3)

  2. C# with C++ functions (Replies: 2)

  3. Fread() C function (Replies: 2)

  4. Random function in C (Replies: 31)

Loading...