We help IT Professionals succeed at work.

Printing a float in c

Anthony Matovu
on
Medium Priority
400 Views
Last Modified: 2012-05-11
I have developed a program that is supposed to a value between -1 to 1  with decimal point.

Every thing seem to work fine only that it prints 0 for all values.

Problem seems to be with this line

printf("\n Correction Coffecient  = %f", (numerator/denominator));

Thanks
#include <stdio.h>
#include <conio.h>
#include <math.h>


main()
   {
int odds[20], i,j,cn,n, prn[20];

long sumxy, sumx, sumy, sumxsqr, sumysqr, denominator, numerator;
float cc;
unsigned long int d1,d2;
 cn=0;
 i=2;

  /* start at 2 for prime numbers becauase 1 is not */

 /*======== to get the prime numbers ========*/

 while (cn<20)
     {
       for(j=2; j<=i; j++)
      {
       if (i % j==0)
	    {
	     if (j==i)
	      {
	     prn[cn] = i;
	     cn++ ;
	      }
	     else{
	      break;
	      }
	    }
      }
	  i++;
	  }


   clrscr();
	   printf("Prime numbers are below");
	   printf("\n=======================");
	   for (n=0; n<20; n++)
	   {
	   printf("\nPrime number: %d ie = %d", n+1, prn[n]);
	   }


/* odd numbers */

cn=0;
i=1;
  printf("\n\nOdd numbers below");
  printf("\n==================");
while (cn<20)
 {
   for(j=i; j<=i; j++)
     {
      if(j%2==1)
       {
       printf("\nOdd number %d is %d",cn+1,j);
       odds[cn]=j;
       cn++;
       }
     }
     i++;

    }


    /*getting the correlation coefficient*/

    sumxy=0;sumx=0; sumy=0; sumxsqr=0; sumysqr=0;numerator=0;denominator=0;d1=0;d2=0;
    for(i=0;i<20;i++)
     {
     sumxy+=(prn[i]*odds[i]);
     sumx+=prn[i];
     sumy+=odds[i];
     sumxsqr+=(prn[i]*prn[i]);
     sumysqr+=(odds[i]*odds[i]);
     }


     numerator=20*sumxy-(sumx*sumy);
     denominator=sqrt(20*sumxsqr-(sumx*sumx))*sqrt(20*sumysqr-(sumy*sumy));

     cc=20/30;  /* (numerator/denominator)*100;*/

     printf("\n sumxy =%d",sumxy);
     printf("\n sun x = %d", sumx);
     printf("\n sum y = %d", sumy);
     printf("\n sum x squared = %d", sumxsqr);
     printf("\n sum y squared = %d", sumysqr);
     printf("\n Numerator = %ld", numerator);
     printf("\n Denominator = %ld", denominator);


   printf("\n Correction Coffecient  = %f", (numerator/denominator));

    getch();

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.