| | |
Please help me to solve C++ program in array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 9
Reputation:
Solved Threads: 0
Please help me to solve the following program in C++ array. After compile message appears "Possible use of "i" before definition.
Thank you in advance.
c++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> void selsort(int [],int); void main() { int AR[50],N,z; clrscr(); cout<<"How many elements do U want to create array with?(max.50)....."; cin>>N; cout<<"\n Enter Array elements.....\n"; for(int i=0;i<N;i++) { cin>>AR[i]; } selsort(AR,N); cout<<"\n\n The sorted array is as shown below.....\n"; for(int i=0;i<N;i++) cout<<AR[i]<<" "; cout<<endl; cin>>z; } void selsort(int AR[],int size) { int small,pos,tmp,i; for(int i=0;i<size;i++) { small=AR[i]; pos=i; } for(int j=(i+1);j<size;j++) { if(AR[j]<small) { small=AR[j]; pos=j; } } tmp=AR[i]; AR[i]=AR[pos]; AR[pos]=tmp; cout<<"\n Array after pass-"<<(i+1)<<"-is:\n"; for(int j=0;j<size;j++) cout<<AR[j]<<" "; }
Last edited by Ancient Dragon; Feb 4th, 2008 at 1:04 am. Reason: add code tags
C++ Syntax (Toggle Plain Text)
... void selsort(int AR[],int size) { int small,pos,tmp,i; for(int i=0;i<size;i++) { ....
if you declared i before, you don't need to do it in the loop.
C++ Syntax (Toggle Plain Text)
... void selsort(int AR[],int size) { int small,pos,tmp; for(int i=0;i<size;i++) { ...
Hope You'll find this information helpful.
An Apple a Day keeps a Doctor away!
•
•
Join Date: Feb 2008
Posts: 1
Reputation:
Solved Threads: 0
c++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> void selsort(int [],int); void main() { int AR[50],N,z; clrscr(); cout<<"How many elements do U want to create array with?(max.50)....."; cin>>N; cout<<"\n Enter Array elements.....\n"; for(int i=0;i<N;i++) { cin>>AR[i]; } selsort(AR,N); cout<<"\n\n The sorted array is as shown below.....\n"; for(int i=0;i<N;i++) cout<<AR[i]<<" "; cout<<endl; cin>>z; } void selsort(int AR[],int size) { int small,pos,tmp,i; for(int i=0;i<size;i++) { small=AR[i]; pos=i; for(int j=(i+1);j<size;j++) { if(AR[j]<small) { small=AR[j]; pos=j; } } } tmp=AR[i]; AR[i]=AR[pos]; AR[pos]=tmp; cout<<"\n Array after pass-"<<(i+1)<<"-is:\n"; for(int j=0;j<size;j++) cout<<AR[j]<<" "; }
Last edited by Ancient Dragon; Feb 4th, 2008 at 1:06 am. Reason: add code tags
•
•
•
•
#include<iostream.h>
#include<conio.h>
void selsort(int [],int);
void main()
{
int AR[50],N,z;
clrscr();
cout<<"How many elements do U want to create array with?(max.50).....";
cin>>N;
cout<<"\n Enter Array elements.....\n";
for(int i=0;i<N;i++)
{
cin>>AR[i];
}
selsort(AR,N);
cout<<"\n\n The sorted array is as shown below.....\n";
for(int i=0;i<N;i++)
cout<<AR[i]<<" ";
cout<<endl;
cin>>z;
}
void selsort(int AR[],int size)
{
int small,pos,tmp,i;
for(int i=0;i<size;i++)
{
small=AR[i]; pos=i;
for(int j=(i+1);j<size;j++)
{
if(AR[j]<small)
{
small=AR[j];
pos=j;
}
}
}
tmp=AR[i];
AR[i]=AR[pos];
AR[pos]=tmp;
cout<<"\n Array after pass-"<<(i+1)<<"-is:\n";
for(int j=0;j<size;j++)
cout<<AR[j]<<" ";
}
╞═══════╣SPYnX███
•
•
Join Date: Oct 2009
Posts: 49
Reputation:
Solved Threads: 6
0
#8 Oct 8th, 2009
C++ Syntax (Toggle Plain Text)
for(int i=0;i<N;i++) cout<<AR[i]<<" "; cout<<endl; cin>>z; }
This part of the code is missing a curly bracket that might be it..
line 17.
//k0ns3rv
![]() |
Similar Threads
- why gets() is skip in this program? (C++)
- What's the HARDEST program you've written? (Computer Science)
- how can i solve error (Java)
- array help (C)
- Why am I getting this output (C++)
- Lottery Program (Java)
- MERGED: Deleting duplicates in an array (plz help me out!!!!!!!) (C)
- Error in c++ program (C++)
- two-dimensional char array (Java)
- How do I create a program using an Array ? (C++)
Other Threads in the C++ Forum
- Previous Thread: please help, I need to move the button up in message box
- Next Thread: animate a triangle in c
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





