Problem with sine function :(

This is a discussion on Problem with sine function :( within the C Programming forums, part of the General Programming Boards category; I can use sine function, but I wanted the Program to display the number without zeros like 0.500000, it works ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    3

    Question Problem with sine function :(

    I can use sine function, but I wanted the Program to display the number without zeros like 0.500000, it works for all number (including 0.5) except sin, cos, and tan answers, I don't get the answer and a loop seems to be unclosed..can anyone help?
    x,y,z, deci_test are double
    deci_chk, deci_cnt, q are int
    Code:
                            z=x*sin(y*(3.14159265/180));
                            deci_test=z;
    			q=0;
    			deci_cnt=0;
    			while (q==0)
    			{
    				deci_chk=deci_test;
    				if (deci_test==deci_chk)
    					q=1;
    				else 
    				{
    					deci_test=deci_test*10;
    					deci_cnt++;
    				}
    			}
    			if (deci_cnt==0)
    				printf("%.0f",z);
    			else if (deci_cnt==1)
    				printf("%.1f",z);
    			else if (deci_cnt==2)
    				printf("%.2f",z);
    			else if (deci_cnt==3)
    				printf("%.3f",z);
    			else if (deci_cnt==4)
    				printf("%.4f",z);
    			else if (deci_cnt==5)
    				printf("%.5f",z);
    			else
    				printf("%f",z);
    if the input is 0.500000 the out put is 0.5
    but if the input is sin(30) the program doesn't display any output and a loop seems to be unclosed.. :-S

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Why not just use "%g"?

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    3
    sorry I'm still a small beginner, can you explain a little?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    3
    omg that's much much better )))))))))
    Thanks pretty much that helped aloooot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating sine function
    By philgrek in forum C Programming
    Replies: 6
    Last Post: 04-18-2011, 08:27 PM
  2. UDF to calculate sine
    By n3cr0_l0rd in forum C Programming
    Replies: 5
    Last Post: 02-26-2009, 07:02 AM
  3. Sine approximation Help
    By What111 in forum C Programming
    Replies: 8
    Last Post: 11-04-2007, 05:22 PM
  4. How to program in the inverse sine function
    By Finchie_88 in forum C++ Programming
    Replies: 4
    Last Post: 03-13-2005, 10:56 PM
  5. A faster way to calculate sine function?
    By IcyDeath in forum C++ Programming
    Replies: 6
    Last Post: 11-06-2004, 12:17 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21