hello everybody,
how invokes the main() function in c/c++ programmes
hello everybody,
how invokes the main() function in c/c++ programmes
srinu
Each program can have only one function called main(). Each function also needs one of the standard header files, iostream, fstream or stdlib, if you are going to be able see results on the screen. main() is a function with a few special properties. First it needs no prototype and no definition. On the other hand it does need a return type, which should be type int, and it does need arguments, although the compiler will provide default arguments if you don't provide them explicitly. To invoke main() just do this:
Code:#include <iostream.h>//or whatever version your compiler uses int main() { cout << "You did it."; return 0; }
i have algoritm and i want to check the number of comparations did, if you can help, send the message please, or code to build in c++, thank you
Please post your algorithm, we can't help you when we don't know what you're doing.
Small example of counting comparisons in a while-loop.
Code:nr_of_comparisons = 0; while (a != b) // the comparison { nr_of_comparisons++; .... }
thank you for your help, my algoritm is the heap sort with numbers, and i want to now how many comparations do the algoritm with c++ code , thank you
(code)
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
#define n 100
void heapsort(int[]);
int i;
void main()
{
int x[n];clrscr();
for(i=0;i<n;i++)
{
x[i]=rand()%99000000+10000000;
}
gotoxy(23,1);
cout<<"NUMEROS DE CONTROL SIN ORDENAR";
gotoxy(23,2);
cout<<"* Demostracion de Heapsort *\n\n";
for(i=0;i<n;i++)
{
cout<<setw(10)<<x[i];
}
cout<<"\n";
getch();clrscr();
heapsort(x);
}
//------------------------------------------------------------------------------
void heapsort(int x[])
{
int i,elt,s,f,ivalue;
for(i=0;i<n;i++)
{
elt=x[i];
s=i;
f=(s-1)/2;
while((s>0)&&(x[f]<elt))
{
x[s]=x[f];
s=f;
f=(s-1)/2;
}
x[s]=elt;
}
for(i=n-1;i>0;i--)
{
ivalue= x[i];
x[i]=x[0];
f=0;
/*s=largeson(0,i-1)*/
if (i==1)
s=-1;
else
s=1;
if((i>2)&&(x[2]>x[1]))
s=2;
while((s>=0)&&(ivalue < x[s]))
{
x[f]=x[s];
f=s;
/*s=largeson(f,i-1)*/
s=2*f+1;
if((s+1<=i-1)&&(x[s]<x[s+1]))
s=s+1;
if (s>i-1)
s=-1;
}/*fin del while*/
x[f]=ivalue;
}/*fin del for*/
/*fin del heapsort*/
//------------------------------------------------------------------------------
gotoxy(23,1);
cout<<"NUMEROS DE CONTROL ORDENADOS\n\n";
for(i=0;i<n;i+=100)
for(s=0;s<n;s++)
{
cout<<setw(10) <<x[i+s];
}
cout<<"\n";
getch();
}
Can you please use the code tage :
if you don't know tell me I will teach you...
C++
The best
You type in this ...
with no spacing ..... just type CODE inside [] and thin when you are done with your code .. type in "/CODE" in "[]"
remeber no spacing
[CODE]
cin>>Code:; cout<< " this is the way"; cin>>[:p/CODE]; cout<< ":rolleyes: I just learned that all yesterday....";
C++
The best
And also check the "Don't Display Smilies" box just above the send button.