Post your C/C++ Programs Here

Status
Not open for further replies.

timemachine

Boom Bhadam Dhishkyao
Re: Post ur C/C++ Programs Here

aditya.shevade said:
^^ No need to go for cygwin just for gcc. Use DevCPP. It uses the win32 portal of gcc, known as mingw32.
MinGW : GTK facility is not available. Lacks of some libraries of gcc.
Downloaded original interface of MinGW but i was not able to find GTK extensions and some binutils.
 

shady_inc

Pee into the Wind...
Re: Post ur C/C++ Programs Here

QwertyManiac said:
Oh and by the way, using unconditional logic jumps ala GoTo is a very bad programming practice.

Hmmm....I find goto quite helpful in the program I have posted..What is the other alternative to it??

Also,How is microsoft visual C++..Better or worse than Dev-C++???
 

timemachine

Boom Bhadam Dhishkyao
Re: Post ur C/C++ Programs Here

Depends upon the requirement of the project.... if i would have to choose, i would have chosen Dev C++. But Visual C++ is also good, but difficult to learn however.
 

The_Devil_Himself

die blizzard die! D3?
Re: Post ur C/C++ Programs Here

yea man dev c++ looks more geeky(hence cool).Lols.dev c++ is light on resources and thats very important for a IDE.
 

timemachine

Boom Bhadam Dhishkyao
Re: Post ur C/C++ Programs Here

Well about looks, it depends person to person. Well i like the UNIX enviornment and the traditional black and white screen for programming. Lotzz of libraries and binutils and a great satisfaction. May vary from person to person
 

Ankur Gupta

Wandering in time...
Re: Post ur C/C++ Programs Here

shady_inc said:
Hmmm....I find goto quite helpful in the program I have posted..What is the other alternative to it??

Also,How is microsoft visual C++..Better or worse than Dev-C++???

Making a function is a much better way to implement goto statement...
Never use goto statement...it is a very inefficient way of programming...
 

ayush_chh

Ambassador of Buzz
Re: Post ur C/C++ Programs Here

Here is program to insert a node in a singly linked list. The program works fine but it gives a warning 'the code is unusable' and if i remove this(bolded part) then the program doesn't work........

Code:
/* Inserting a node into a singly Linked List*/

#include<stdio.h>
#include<conio.h>
struct list
{
 int info;
 struct list *link;
};
typedef struct list node;
// create the list
void createlist(node *n)
{
 char ch;
 printf("\n\nEnter the item (number only) to be inserted\n");
 scanf("%d",&n->info);
 printf("\nDo you want to continue(Y/N)\n");
 ch= getche();
 getch();
 if(ch=='y'|| ch=='Y')
 {
  n->link=(node *)malloc(sizeof(node));
  createlist(n->link);
 }
 else
 n->link=NULL;
}
void displaylist(node *n)
{
 node *n1;
 n1=n;
 if(n1!=NULL)
 {
  printf("%d\n",n->info);
  displaylist(n1->link);
 }
}
void insnode(node *n,int desti)
{
 int cnt=1;
 node *n1, *temp;
 n1=n;
 while(n1!=NULL)
 {
  cnt++;
  if(desti==1)
  {
   temp->link=(node *)malloc(sizeof(node));
   printf("\nEnter the item to be inserted\n");
   scanf("%d",&temp->info);
   temp->link=n1;
   n=temp;
   [B]n1->link;[/B]
   printf("\nNode Inserted Successfully\n");
   printf("\nThe new Linked List elements are\n");
   break;
  }
  else if(desti==cnt)
  {
   temp->link=(node *)malloc(sizeof(node));
   printf("\nEnter the item to be inserted\n");
   scanf("%d",&temp->info);
   temp->link=n1->link;
   n1->link=temp;
   printf("\nNode Inserted Successfully\n");
   printf("\nThe new Linked List elements are\n");
   break;
  }
  n1=n1->link;
 }
 displaylist(n);
}
void main()
{
 node *start;
 int loc;
 clrscr();
 start->link=(node *)malloc(sizeof(node));
 printf("\nCreate a linked list :");
 createlist(start);
 printf("\n\nCreated linked list elements are:\n");
 displaylist(start);
 printf("\nEnter the position at which you want to add new node\n");
 scanf("%d",&loc);
 insnode(start,loc);
 getch();
}
 
Last edited:

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

timemachine said:
MinGW : GTK facility is not available. Lacks of some libraries of gcc.
Downloaded original interface of MinGW but i was not able to find GTK extensions and some binutils.

^^ Yes.. but I am not sure if GTK is cross platform.... correct me if I am wrong. The man just wants to program C. And on any given day, using Linux and gcc is better than cygwin.

I have seen the roughs of cygwin. Using Linux is far better.
 

timemachine

Boom Bhadam Dhishkyao
Re: Post ur C/C++ Programs Here

aditya.shevade said:
^^ Yes.. but I am not sure if GTK is cross platform.... correct me if I am wrong. The man just wants to program C. And on any given day, using Linux and gcc is better than cygwin.

I have seen the roughs of cygwin. Using Linux is far better.

You are right. But it is good for those who knows nothing about UNIX or LINUX systems and can't keep them as a OS because they know nothing. They only want to program with gcc and rest use the features of windows(because they love it). Besides the roughs of cygwin, it can be used for beginning, and then it is good to switch over unix or linux. A desktop linux like mandriva is easy to install, dual - boot , and use. And u r right, using Linux or unix with gcc is best. I use it on a seprate machine, windows on a seprate one.
 

mehulved

18 Till I Die............
Re: Post ur C/C++ Programs Here

aditya.shevade said:
^^ Yes.. but I am not sure if GTK is cross platform.... correct me if I am wrong. The man just wants to program C. And on any given day, using Linux and gcc is better than cygwin.

I have seen the roughs of cygwin. Using Linux is far better.
GTK is surely available on windows. There's gaim/pidgin and gimp both available for windows. The former surely makes use of GTK on Windows, not sure of the latter.
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

GIMP definitely uses GTK2+ Environment. If I remember correctly, you are required to install it before installing the GIMP itself.
 

Zeeshan Quireshi

C# Be Sharp !
Re: Post ur C/C++ Programs Here

The_Devil_Himself said:
^^thanks for confirming.Dev c++ has very good gui too.
dud then u seriously need to use Visual C++ Express or Eclipse . You'll forget DevC++ after using them .

Download Visual C++ 2005 Express Here [FREE]:
*msdn2.microsoft.com/hi-in/express/aa700735.aspx

or you can down Eclipse C++ Developer Pack Here [FREE}:
*www.eclipse.org/downloads/

The only problem with Eclipse is , t does not Bundle a Compiler with it . so you need to Install GCC(MinGW or Cygwin or DJGPP on Windows) before installing it and then configure it to use ur Installation of GCC , whereas Visual C++ 2005 Express bundles everything into a neat package .
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

mehulved said:
GTK is surely available on windows. There's gaim/pidgin and gimp both available for windows. The former surely makes use of GTK on Windows, not sure of the latter.

hmm... I think I should do a little digging on it and see if I can program my project for this year in GTK and port it to windows..... Hoping for the best.
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

@shady_inc : Why thank you. :)

@ ayush_chh :
From what I've read of the insnode() function, the code is a mess.

For example, you're mallocing a block of memory at temp->link, without ever initializing temp.

The second thing is, the statement you've bolded, ie n1->link;, isn't supposed to do anything by itself. Perhaps you meant n1->link = temp or something?

EDIT : On further study, I think what you meant was :

Code:
if(desti==1)
  {
   [B]temp[/B]=(node *)malloc(sizeof(node));
   printf("\nEnter the item to be inserted\n");
   scanf("%d",&temp->info);
   temp->link=n1;
   n=temp;
   [B]/*n1->link;*/[/B]
   printf("\nNode Inserted Successfully\n");
   printf("\nThe new Linked List elements are\n");
   break;
  }
 
Last edited:

quan chi

mortal kombat
Re: Post ur C/C++ Programs Here

well how to get the 40th fibonacci numer.
the below only calculates upto 20 i think.
Code:
#include<iostream.h>
int fib(int n);
int main
{int n,answer;
cout<<"enter a number"<<endl;
cin>>n;
answer=fib(n);
cout<<answer<<"is the"<<n<<"th fibonacci number"<,endl;
return(0);
}
int fib(int n)
{if(n<3)
{return(1);
}
else
{return(fib(n-2)+fib(n-1));
}
}
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

^^^ Are you asking how to calculate up to the 40th, because you're unable to reach past 20? If that's the case, declare your variables as unsigned long, and then try it.
 

Zeeshan Quireshi

C# Be Sharp !
Re: Post ur C/C++ Programs Here

@quan_chi , it would me much more efficient(actually bout Infinitely Efficient) to solve the program iteratively rather than recursively .

Also u can use BNU Multi Precision library if you want to work with Infinite(literally) precision .
*gmplib.org/

this way u can calculate as big as ur RAM allows to with no size restraints :)
 

quan chi

mortal kombat
Re: Post ur C/C++ Programs Here

Sykora said:
If that's the case, declare your variables as unsigned long, and then try it.
by that it dosent show any answer it freezes for some time and returns to the program page.

Zeeshan Quireshi said:
@quan_chi , it would me much more efficient(actually bout Infinitely Efficient) to solve the program iteratively rather than recursively .

Also u can use BNU Multi Precision library if you want to work with Infinite(literally) precision .
*gmplib.org/

this way u can calculate as big as ur RAM allows to with no size restraints :)

well can you please tell me in detail what it is and how to use it .
 
Last edited:
Status
Not open for further replies.
Top Bottom