Click to See Complete Forum and Search --> : small C program from a new bie
simbarashe
January 15th, 2003, 02:42 AM
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
MartinL
January 15th, 2003, 08:55 AM
And? What is your problem???
pareshgh
January 15th, 2003, 12:27 PM
Martin,
I think its a college based programs.
:D
mwilliamson
January 15th, 2003, 07:18 PM
2.1
int number;
cin >> number;
cout << number << (number % 2) ? " is odd" : " is even";
Whats the prize?
MartinL
January 16th, 2003, 03:46 AM
I offer you beer...
Finally I know which number is odd... :D
WillemM
January 16th, 2003, 11:04 AM
Cool, I didn't know my computer could discover if an integer was even or odd.
MartinL
January 16th, 2003, 01:20 PM
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#... :D:D:D
This is the 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
pareshgh
January 16th, 2003, 02:02 PM
for an integer to be perfect..
double d = 1.10
int i = (int) d; // 1
if ( (double ) (d - i ) == 0 )
its perfect integer
:D
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.