CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Apr 2002
    Location
    zimbabwe
    Posts
    13

    small C program from a new bie

    Can some one help me on these problems

    a.) Write a program to input the original price of an item and of d, and
    determine on what day the price drops to less than half the original
    price.
    b.) Write a program to input an integer in between 1-9 and print a line of
    output consisting of a line of digits from 1-n followed by descending digits
    from n-1.

    2.Write a program to read a positive integer to determine

    1)whether the integer is even or odd
    2)whether the integer is prime or not
    3)whether the integer is a perfect

  2. #2
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    And? What is your problem???

  3. #3
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    Martin,
    I think its a college based programs.


  4. #4
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    2.1

    int number;
    cin >> number;
    cout << number << (number % 2) ? " is odd" : " is even";

    Whats the prize?
    Last edited by mwilliamson; January 16th, 2003 at 01:44 PM.

  5. #5
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    I offer you beer...

    Finally I know which number is odd...

  6. #6
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    Cool, I didn't know my computer could discover if an integer was even or odd.
    WM.

    What about weapons of mass construction?

  7. #7
    Join Date
    Dec 2000
    Location
    Slovakia
    Posts
    1,043
    Yea, guys... I have discovered new method how to determine if an integer is even or odd...

    As you can see in the attached code, this method is more sophisticated, easier to understand and really looking good!!!

    And additionaly, it is written in C#...

    This is the code:
    Code:
    using System;
    
    namespace Skuska
    {
    	class Class1
    	{
    		static private double angle1 = Math.PI / 3;
    		static private double angle2 = Math.PI / 3.2;
    
    		static public bool IsNumberEven(int iNum)
    		{
    			return (iNum / (int)(Math.Log(Math.E, Math.E) + (Math.Sin(angle1)*Math.Sin(angle1))
    				+ (Math.Cos(angle1) * Math.Cos(angle1))))==(((int)(Math.Cosh(angle2)+iNum+Math.Sqrt( 
    				(Math.Sin(angle2)*Math.Sin(angle2))+(Math.Cos(angle2)*Math.Cos(angle2))
    				-(Math.Tanh(angle2)*Math.Tanh(angle2)))-(int)((2*Math.Sin((angle1-angle2)/2)
    				*Math.Cos((angle1+angle2)/2))/(Math.Sin(angle1)-Math.Sin(angle2)))))/
    				((int)((Math.Log(Math.E, Math.E) + (Math.Sin(angle2)*Math.Sin(angle2)) + 
    				(Math.Pow(Math.Cos(angle2), 2))))));
    		}
    
    		[STAThread]
    		static void Main(string[] args)
    		{
    			while (true)
    			{
    				int iNum = 0;
    
    				Console.Write("Enter an integer (or empty line to quit):");
    				string sInput = Console.ReadLine();
    				if (sInput == "")
    					break;
    
    				iNum = Int32.Parse(sInput);
    
    				Console.WriteLine("Integer " + iNum.ToString() + " is " + (IsNumberEven(iNum)?"Even":"Odd"));
    				Console.WriteLine();
    			}
    		}
    	}
    }
    Martin

  8. #8
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    for an integer to be perfect..

    double d = 1.10
    int i = (int) d; // 1

    if ( (double ) (d - i ) == 0 )
    its perfect integer


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured