Thread: an intresting problem!!! plz help me

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    22

    Exclamation an intresting problem!!! plz help me

    hi
    this program can get the integral of the polynomial function but, an intresting thing is that doesn't work truth.
    exaple for 3x^3+2x^2+1x^1+4x^0
    this program get integral 2.25x^4+1.33x^3+0.5x^2+4x^1
    this mean only two end array works truth!!!
    why? plz help me
    (sorry for my bad english )

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    
    void integral(float *, int);
    
    int main(){
    float *p;
    int n,i;
    printf("how much sentence: ");
    scanf("%d",&n);
    p=(float *) malloc (sizeof (float) *(n));
    
    if(!p)
    {
    printf("allocation failed");
    exit(1);
    }
    for(i=1;i<n;i++){
    printf("enter coefficient of %d's sentence: ",i);
    scanf("%f",&p[i]);
    }
    printf("enter fixed amount: ");
    scanf("%f",&p[0]);
    
    
    integral(p,n);
    
    getch();
    return 0;
    }
    
    
    void integral(float *p, int n){
    int i;
    
    
    for(i=n-1;i>=0;--i)
    p[i]=p[i]/(i+1);
    
    printf("\n\nintegral is: ");
    for(i=n-1;i>=0;i--)
    printf("+%3.2fx^%d",p[i],i+1);
    
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    22
    oh, this program works but in main program this cant work!!!
    Code:
    int main(){
    float *p;
    int n,m,i;
    printf("tabe chand jomlei bashad: ");
    scanf("%d",&n);
    p=(float *) malloc (sizeof (float) *(n));
    
    if(!p)
    {
    printf("allocation failed");
    exit(1);
    }
    for(i=1;i<n;i++){
    printf("zaribe jomleye %d ra vared konid: ",i);
    scanf("%f",&p[i]);
    }
    printf("meghdare sabet ra vared konid: ");
    scanf("%f",&p[0]);
    
    printf("\nmeghdari ra vared konid ta meghdare tabe asli, va moshtagh hesab shavad: ");
    scanf("%d",&m);
    
    tabe(p,n,m);
    moshtagh(p,n,m);
    antegral(p,n);
    
    getch();
    return 0;
    }
    
    void tabe (float *p,int n,int m){
    int i;
    float ans=p[0];
    
    printf("\ntabe asli:\n");
    
    for(i=n-1;i>=0;i--)
    printf("+%3.2fx^%d",p[i],i);
    
    for(i=n-1;i>=1;i--)
    ans=pow (m,i)*p[i]+ans;
    
    printf("\nmeghdare tabe bar asase meghdare %d mishavad: %3.2f",m,ans);
    }
    
    
    void moshtagh (float *p, int n, int m){
    int i;
    float ans;
    
    for(i=n-1;i>0;i--)
    p[i]=p[i]*i;
    
    printf("\n\nmoshtaghe tabe:\n ");
    for(i=n-1;i>0;i--)
    printf("+%3.2fx^%d",p[i],i-1);
    
    ans=p[1];
    
    for(i=n;i>1;i--)
    ans=ans+pow(m,i-1)*p[i];
    
    printf("\nmeghdare moshtaghe tabe bar asase meghdare %d mishavad: %3.2f",m,ans);
    }
    
    void antegral(float *p, int n){
    int i;
    
    
    for(i=n-1;i>=0;--i)
    p[i]=p[i]/(i+1);
    
    printf("\n\nantegrale tabe: ");
    for(i=n-1;i>=0;i--)
    printf("+%3.2fx^%d",p[i],i+1);
    
    }

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    22
    my problem solved. sorry for my post. I'm not crazy!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  2. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 12:32 AM
  3. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM
  4. !!!!!Very intresting!!!!!
    By lukas1viper in forum C++ Programming
    Replies: 4
    Last Post: 01-13-2002, 05:30 AM
  5. Texture Problem(I got the NeHe tut working, but I have a problem)
    By SyntaxBubble in forum Game Programming
    Replies: 2
    Last Post: 12-02-2001, 10:40 PM