Turbo C/C++ and other junk compilers help, discussions and queries here

nbaztec

Master KOD3R
@somulesnar,

Apologies if you got offended mate. I did not mean that. What I emphasized upon was you got the code from there and didn't map it correctly hence it was inside the class. If you correctly accredit the original source, people here can better inform you what you are doing wrong, and not just about the code, but the practices as well.
 

somulesnar

Journeyman
^^ Its alright buddy. I ama a novice and i am very eager to expertise in this language. Hope that i ll get more help when i post some more codes in future.
Cheers.
 

somulesnar

Journeyman
Re: C/C++ Beginner's Guide and Post Basic Questions here

Here's is a simple bubble sort program.

#include<stdio.h>
#include<conio.h>
int main()
{
int arr[5]={33,1,42,78,2};
int i,j,temp;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("The array after sorting is:\n ");
for(i=0;i<=4;i++)
printf("\n%d",arr);
getch();
}
 
Last edited:

nbaztec

Master KOD3R
Re: C/C++ Beginner's Guide and Post Basic Questions here

Here's is a simple bubble sort program.

#include<stdio.h>
#include<conio.h>
main()
{
int arr[5]={33,1,42,78,2};
int i,j,temp;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("The array after sorting is:\n ");
for(i=0;i<=4;i++)
printf("\n%d",arr);
getch();
}


The default return value for a function in C is int. You're not returning anything. Indent your code.
 

somulesnar

Journeyman
Re: C/C++ Beginner's Guide and Post Basic Questions here

^^But in C if the coder doesnt specify the return type it means that it can return any type of data. Infact the compiler doesnt show any errors and the code executes prorperly.
 

nbaztec

Master KOD3R
Re: C/C++ Beginner's Guide and Post Basic Questions here

No. That's incorrect.

Which compiler are you using?
 

somulesnar

Journeyman
Re: C/C++ Beginner's Guide and Post Basic Questions here

oops sorry i was wrong. was thinking of something else. post has been deleted. And the code has been edited. thnx for the correction.
 

skeletor

Chosen of the Omnissiah
Four things:

1) Indent your code.
2) Use [ code ] ***** [ /code ] instead of spoiler.
3) Use an ANSI compliant compiler. Otherwise you are not learning C/C++, but just wasting your time.
4) Post in the Beginner C/C++ thread only if you're writing ANSI compliant code. Not outdated stuff using an outdated compiler. (Turbo C/C++)
 

somulesnar

Journeyman
Re: C/C++ Beginner's Guide and Post Basic Questions here

Code:
 #include<stdio.h>
#include<conio.h>
float factorial(int);
void main()
{
	int i;
	int f;
	clrscr();
	printf("Enter the number: ");
	scanf("%d",&i);
	f=factorial(i);
	printf("\nThe factorial of the entered number is: %d",f);
	getch();
}
float factorial(int n)
{
	if(n==1)
	return(1);
	else
	return(n*factorial(n-1));
}

Factorial using Recursion.
 

nbaztec

Master KOD3R
Re: C/C++ Beginner's Guide and Post Basic Questions here

Code:
 #include<stdio.h>
#include<conio.h>
float factorial(int);
void main()
{
	int i;
	int f;
	clrscr();
	printf("Enter the number: ");
	scanf("%d",&i);
	f=factorial(i);
	printf("\nThe factorial of the entered number is: %d",f);
	getch();
}
float factorial(int n)
{
	if(n==1)
	return(1);
	else
	return(n*factorial(n-1));
}

Factorial using Recursion.

Again, trotting past the fact that you are writing non-standard code, you've failed to return value from main().
 

digit.sh

Journeyman
Re: C/C++ Beginner's Guide and Post Basic Questions here

Code:
 #include<stdio.h>
#include<conio.h>
float factorial(int);
void main()
{
	int i;
	int f;
	clrscr();
	printf("Enter the number: ");
	scanf("%d",&i);
	f=factorial(i);
	printf("\nThe factorial of the entered number is: %d",f);
	getch();
}
float factorial(int n)
{
	if(n==1)
	return(1);
	else
	return(n*factorial(n-1));
}

Factorial using Recursion.

For god's sake do not use those nonstandard functions like clrscr() and conio.h crap. If your compiler doen't let you compile without those things, get rid of the compiler. Code::blocks is free, why don't use that?
And follow a better book. "The C programming language(ANSI)" by Kernighan and Ritchie is the best. Also there are "C in a nutshell" by Peter Prinz. and there are good online tutorials for C. Maintain the STANDARD. Please!:|
 

skeletor

Chosen of the Omnissiah
well, there was a reason why I said not to learn C as your first language in India. You're most likely to choose the wrong path. Indians have raped the beautiful language by sticking with Turbo C/C++ and writing useless books. eg, Sumita Arora, Yashavant Kanetkar etc. :(

The C Programming Language 8120305965: Book: Brian W. Kernighan (9788120305960) | Flipkart.com

Buy this. Very cheap and this is written by the creators of C.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
^^Isn't this too complicated for newbies to programming..??

Well don't count me in for of Turbo C/C++ ofcourse. I myself use GCC too. But I find The C Programming Language and Thinking in C++ too hard for a newbie.

Specially thinking in C++ explains everything from the starting using pointer and all, which I personally find really hard to grasp as a newbie to C++.

So any good book recommendations for C++ is welcome.

PS : I know both C and C++, but as usual, I read Kaneetkar and Balaguruswamy which is not Standand C / C++. So I'm looking further to get my base better.
 

digit.sh

Journeyman
^^Isn't this too complicated for newbies to programming..??

Well don't count me in for of Turbo C/C++ ofcourse. I myself use GCC too. But I find The C Programming Language and Thinking in C++ too hard for a newbie.

Specially thinking in C++ explains everything from the starting using pointer and all, which I personally find really hard to grasp as a newbie to C++.

So any good book recommendations for C++ is welcome.

PS : I know both C and C++, but as usual, I read Kaneetkar and Balaguruswamy which is not Standand C / C++. So I'm looking further to get my base better.

^^ You already know C. You shouldn't find K&R hard to grasp. K&R is a must for someone keen to learn C. Not only its authentic, its beautifully written too.

Anyway, I found the following:
1> C Tutorial - Learn C - Cprogramming.com
2> C Programming
3> C Tutorial
4> *phy.ntnu.edu.tw/~cchen/ctutor.pdf
5> ftp://ftp.math.uh.edu/pub/sanders/Math6378-sp12/Documents/C+F77/oxford-CTutorial.pdf

Among the above links, 1 and 2 are more basic than the rest. So they may qualify as "for beginners". No. 4 is good but it follows the GNU standard of C, which means its not platform neutral in some cases. No. 5 is absolutely platform neutral and the best IMO. It strictly follows the ANSI standard and points out differences from "K&R" standard where it matters. I liked 4 and 5 the most.:wink:
Happy learning:wink:
 

Liverpool_fan

Sami Hyypiä, LFC legend
Head First C. :)
And yes, always report the cases of non-standard code floating around outside this thread. They always need to be thrown into this trash thread, designed for the losers to ask questions for their loser queries and for sympathetic posters to help them.
And oh not another book discussion please. The main C/C++ sticky is nothing except newbies asking for books without even going through the thread OP. Same answers being rehashed again, and again.
 

nims11

BIOS Terminator
^^Isn't this too complicated for newbies to programming..??

Well don't count me in for of Turbo C/C++ ofcourse. I myself use GCC too. But I find The C Programming Language and Thinking in C++ too hard for a newbie.

Specially thinking in C++ explains everything from the starting using pointer and all, which I personally find really hard to grasp as a newbie to C++.

So any good book recommendations for C++ is welcome.

PS : I know both C and C++, but as usual, I read Kaneetkar and Balaguruswamy which is not Standand C / C++. So I'm looking further to get my base better.

Thinking in C++ is not for beginners. It is for people comfortable with C or basic C++.

Regarding standards, i don't feel they play any role in determining how much the programmer learns as switching standards is not a big deal although sticking to the current standard is the always better. A newbie won't be using stuffs like STL and dynamic casts anyway!
 
Top Bottom