Jump to content

programming in c


cdinesh1

Recommended Posts

isnt the search for a formula for calculating prime numbers one of the great mysterys of mathematics, no wait i might be getting confused. I think i the mystery is the way of telling if a number is prime. Dont worry i will hopefully regain my sanity soon.

Link to comment
Share on other sites

Well, use your brain a little. For a start, you can immediately disclude all of the even numbers since 2 divides any even number. There's millions of articles on this; just do a search on Wikipedia and you're bound to find something.

 

For your information, the "great question" you were talking about is a formula for generating the n'th prime number. This is currently an unsolved problem.

Link to comment
Share on other sites

With regards to the palindrome check, if you simply convert the integer to a string (trivial, there'll be plenty of examples of this around, just using mod 10 and division to work out the digits and then adding a constant to put it in the right ascii range). Then you can do something like -

 


  int palindrome ( char *theString )
  {
      unsigned int length = strlen( theString ) - 1;
      unsigned int counter = 0;
      int palindromeFlag = 1;
      while ( counter < length ) {
          if ( theString[counter] != theString[length] ) {
              palindromeFlag = 0;
              break;
          }
          length--;
          counter++;
      }
      return palindromeFlag;
  };

 

Obviously you would need to make sure when generating the string you null terminate it (ie this isnt a fully functioning stand alone code segment, you need a main() function and some IO stuff and conversion) but it might give you an idea of how to go about things. You might be able to do the same thing but without converting it into a string (ie by doing the checks for equality as you convert from the whole number to its digits without adding the additional constant to convert to ascii) but it was easier just to knock this one together quickly to give you an idea.

Link to comment
Share on other sites

if it isn't a homework assignment i would be willing to help out, the easiest way (well the way i always use) is

 

char* x = new char[10];

int the_number = 37;

sprintf(x, "%d", the_number);

 

as far as figuring out if the number is prime, it is easy enough to do if you follow the rules and don't mind speed.. obviously all numbers less than half the set to check, and if if it doesn't divide easily (look up the % operator, also remember to use a double and compare it to itself rounded to nearest 1).. this is all if you don't care about speed..

Link to comment
Share on other sites

This all very facinating. I have just recently started to study the C and C++ languages, but where do I get a good working compiler for free. I don't have hundreds to spend on simple compilers that microsoft enevitable charges a price that almost rivals the goss national product of some small countries.

Link to comment
Share on other sites

This all very facinating. I have just recently started to study the C and C++ languages, but where do I get a good working compiler for free. I don't have hundreds to spend on simple compilers that microsoft enevitable charges a price that almost rivals the goss national product of some small countries.

 

http://bloodshed.net/dev/

 

Is the one I use, and its one of the best I think :)

 

Cheers,

 

Ryan Jones

Link to comment
Share on other sites

Gcc!!!

 

GCC is more for the advanced user, Dev-C++ fits for basic too advanced (Features for all).

 

I really reccomend Dev-C++ for basic users and maybe for advanced users but GCC may be more too their liking :)

 

Cheers,

 

Ryan Jones

Link to comment
Share on other sites

Dev-C++ is not a compiler, it´s a developement enviroment. Actually, I thought Dev-C++ uses gcc as compiler but I´m not sure about that.

 

EDIT:

Bloodshed Dev-C++ is a full-featured Integrated Development Environment (IDE) for the C/C++ programming language. It uses Mingw port of GCC (GNU Compiler Collection) as its compiler. It creates native Win32 executables' date=' either console or GUI. Dev-C++ can also be used in combination with Cygwin. [/quote']

Now if I only knew what "Mingw port of GCC" is ...

Link to comment
Share on other sites

Dev-C++ is not a compiler' date=' it´s a developement enviroment. Actually, I thought Dev-C++ uses gcc as compiler but I´m not sure about that.

[/quote']

 

Isn't that the point? Its better for basic users those who just started learning C / C++? The syntax highlighting also helps me find errors :D

 

Cheers,

 

Ryan Jones

Link to comment
Share on other sites

Isn't that the point? Its better for basic users those who just started learning C / C++? The syntax highlighting also helps me find errors :D

 

Cheers' date='

 

Ryan Jones[/quote']

 

 

My votes always go for a text editor with syntax highlighting and a nice compiler like GCC... I'm for throwing people in the deep end, makes transitions in later life easier :) But that's just a personal thing...

Link to comment
Share on other sites

My votes always go for a text editor with syntax highlighting and a nice compiler like GCC... I'm for throwing people in the deep end, makes transitions in later life easier :) But that's just a personal thing...

 

 

Thats the way I started out - I found it quite easy but from helping others learn I found that its best not to start that way for most peple - too much uts them off :( But if it works go for it!

 

Cheers,

 

Ryan Jones

Link to comment
Share on other sites

This all very facinating. I have just recently started to study the C and C++ languages, but where do I get a good working compiler for free. I don't have hundreds to spend on simple compilers that microsoft enevitable charges a price that almost rivals the goss national product of some small countries.

MS Visual C++ express edition 2005 is free until Nov 2006.

http://msdn.microsoft.com/vstudio/express/visualc/download/

Link to comment
Share on other sites

MS Visual C++ express edition 2005 is free until Nov 2006.

http://msdn.microsoft.com/vstudio/express/visualc/download/

I´m lazy so I´ll ask you instead of looking it up from the page you linked to: What does "it´s free until Novemver" mean? Does it mean "get it till November, afterwards you´ll have to pay for it" or does it mean "when you get it now, you can use it till November for free, afterwards you´ll have to register"?

Link to comment
Share on other sites

Sorry to interfere - the discussion has already gone off topic anyway.

 

I've been learning C++ (From http://www.cplusplus.com/doc/tutorial/)

I'm about half-way through the tutorials. I'm using the Dev-c++ as the IDE.

 

I was wondering what type of programs could I to make with the language.

I was thinking of starting a password program. That's all I could think of. Could someone give me any hints as to other software I could potentially make with the C++ language.

 

Thanks

(understanding I'm still a newbie learning the language).

Link to comment
Share on other sites

I was wondering what type of programs could I to make with the language.

I was thinking of starting a password program. That's all I could think of. Could someone give me any hints as to other software I could potentially make with the C++ language.

 

C programs can do anything you need given sufficient knowledge, well almost but there are some things you can't do but would be of no concern to the average programmer and involve writing code in ASM.

 

Pick something simple to start with and then develop it - you'll learn a lot and pick up ideas for other programs along the way :)

 

Good luck!

 

Ryan Jones

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.