my c programs
Started by bobwrit, Apr 12 2007 01:30 PM
4 replies to this topic
#1
Posted 12 April 2007 - 01:30 PM
here's some of my programs. there all in c. tell me what you think of them.
|
|
|
#2
Posted 14 April 2007 - 09:30 AM
Nice collection there! Some good math stuff there:
arcsine.cpp
case_geo.cpp
cos.cpp
sine.c
tan.cpp
arcsine.cpp
case_geo.cpp
cos.cpp
sine.c
tan.cpp
#3
Posted 14 April 2007 - 11:16 PM
Which editor are you using? I'm using Dev-C++ and the code looks very strange, with biiiig indents, and stuff like that. I prefer an indent of 2-4 spaces in size.
It's generally a bad idea to use libraries such as conio, when it can be done without. You're trying to use the function, clrscr(), but it have never been a part of the conio-header.
conio.h: Conio.h - Wikipedia, the free encyclopedia
I did go trough all the source, looking for code to be optimized.
In var.c, line 13, you're doing like this:
In ifbegini.cpp you're using main with no return-type, but still returns something.
1. You can't return anything with no return-type.
2. main() with any other return type than int, have never been standard-C nor C++.
In the same code, I would also suggest you to use a switch-statement, instead of the if...else if...else-statement. I will make a nicer-looking-code, imho. The same thing I'll say about geometry.cpp, and much of the other code. Generally you're using no return-type for the main()-function, or you're using void, which is also wrong.
You generally have to know whenever it's C or C++-code. Your files is changing between .C and .CPP-extensions, but all the code is C, so it should only be .C, for all the files.
It's generally a bad idea to use libraries such as conio, when it can be done without. You're trying to use the function, clrscr(), but it have never been a part of the conio-header.
conio.h: Conio.h - Wikipedia, the free encyclopedia
I did go trough all the source, looking for code to be optimized.
In var.c, line 13, you're doing like this:
clas = clas++;Why use the assignment-operator. I know it's the same result, but why not just use
clas++;This will be "translated" into
clas = clas + 1;So you're old thingy will look like this
clas = clas = clas + 1;
In ifbegini.cpp you're using main with no return-type, but still returns something.
main() // Oops
{
// ...
return 0;
There's two things wrong in this. 1. You can't return anything with no return-type.
2. main() with any other return type than int, have never been standard-C nor C++.
In the same code, I would also suggest you to use a switch-statement, instead of the if...else if...else-statement. I will make a nicer-looking-code, imho. The same thing I'll say about geometry.cpp, and much of the other code. Generally you're using no return-type for the main()-function, or you're using void, which is also wrong.
You generally have to know whenever it's C or C++-code. Your files is changing between .C and .CPP-extensions, but all the code is C, so it should only be .C, for all the files.
#4
Posted 15 April 2007 - 12:19 PM
I was useing two compilers, mingw and turbo c++. I wrote most of them for a class that I have in c. I do have a tendency to swich my extentions. depending on the compiler typicaly the main without any type returning something is a warning and dosen't do anything to the code. I could leave out the return 0; code out of it if I wanted to but I didn't.
#5
Posted 01 October 2007 - 05:46 AM
very nice stuffs


Sign In
Create Account



Back to top









