[ create a new paste ] login | about

Link: http://codepad.org/i0Epm5IS    [ raw code | output | fork ]

C, pasted on Dec 8:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double calPow()
{
   FILE *filePointer;
   filePointer=fopen("result.txt","w+") ;
   int i,j;
   double Rint[i], RL, temp;
   double  Rtest[i], PowerRL[i], PowerRint[i];
   int VCC;
   if (filePointer)
   {
    for(i=0;i<201;i++)
       {Rtest[i]=RL-100+i;
        PowerRL[i]=((VCC *(Rtest[i]/(RL+Rtest[i])))*(VCC *(Rtest[i]/(RL+Rtest[i]))))/Rtest[i] ;
        PowerRint[i]=((VCC *(Rint[i]/(RL+Rtest[i])))*(VCC *(Rint[i]/(RL+Rtest[i]))))/Rtest[i];

           printf("\n       RL   Rint      Power    Power");
           printf("\n                       Rint       RL");
           fprintf(filePointer, "\n %.2f  %.2f      %.15f        %.15f",RL,Rint,PowerRint,PowerRL);   // printing all the data to a file.
       }
    for(j=i+1;j<201;j++)
       {
           if (PowerRL[i]<PowerRL[i]){
            temp = PowerRL[i];
            PowerRL[i]=PowerRL[j];
            PowerRL[j]=temp;
            temp = PowerRint[i];
            PowerRint[i]=PowerRint[j];
            PowerRint[j]=temp;
            temp = Rtest[i];
            Rtest[i]=Rtest[j];
            Rtest[j]=temp;
           }
       }
       fclose(filePointer);
   }
   return 0;
}
int main( )
{
   int VCC;
   float Rint,RL=0,Pmax=0;
   printf("\nNew power supply voltage between 1 and 15 VDC: \n");
   scanf("%d",&VCC);
   printf("\nEnter a valid internal resistance (Rint) range between 200 and 5k ohms: \n");
   scanf("%f",&Rint);
   if(VCC>=1 && VCC<=15)
   {
       if(Rint>=200 && Rint<=5000)
       {
           RL = Rint-100;
           Pmax = calPow(VCC,Rint,RL);       //here you are getting some value from calPow and assigning to float variable. Then the function should be float
           printf("\nMaximum power transferred to RL is : %.2f\n",Pmax);
       }
       else
           printf("\n The entered values of Rint is out of range and may damage the equipment.");
   }
   else
       printf("\n The entered values of V is out of range and may damage the equipment. ");
   return 0;
}


Output:
1
2
3
4
5
6

New power supply voltage between 1 and 15 VDC: 

Enter a valid internal resistance (Rint) range between 200 and 5k ohms: 

 The entered values of V is out of range and may damage the equipment. 


Create a new paste based on this one


Comments: