Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 7:43 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: c++/data structure
PostPosted: Wed Oct 27, 2010 11:37 pm 
Offline
Newbie
User avatar

Joined: Wed Oct 27, 2010 11:20 pm
Posts: 2
Has thanked: 0 time
Have thanks: 1 time

my problem :is write a sequential search method that finds the last occurrance of an item
the program runs but it doesnot give me the right answer
Code:
#include<iostream>
using namespace std;
  int seqsearch(int seq[],int size,int key)
{
int i;

for(i=size;i>0;i--)
{
if(seq[i]==key)
return i ;


} return -1 ;
}

  int main()

  {
     int i;
    
    
      int key;
      int seq[]={0,1,2,3,4,5,6,7,8,9};
      
int x=seqsearch(seq,10,key);
   cout<<"enter the key"<<endl;
   cin>>key;

   cout<<x<<endl;
   

  return 0;
  }



TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: c++/data structure
PostPosted: Sat Oct 30, 2010 12:16 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2272
Location: Earth
Has thanked: 39 time
Have thanks: 61 time
fix like this
Code:

for(i=size;i>=0;i--)
{
if(seq[i]==key)
return i ;


} return -1 ;


and
Code:
int main()

  {
     int i;
     
     
      int key;
      int seq[]={0,1,2,3,4,5,6,7,8,9};
     

   cout<<"enter the key"<<endl;
   cin>>key;
// Call the function after the entry of key
int x=seqsearch(seq,10,key);
   cout<<x<<endl;
   

  return 0;
  }


_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 ASP file structure
 Appriori witn uncertain data
 Data Encryption Standard (DES)
 data leakage detection coding in java
 How to make PHP form data saved into txt file
 charm algorithm in data mining
 Des java Applet ( Data Encryption Standards )
 How to merge the data into file
 What is Customer Data Integration or CDI?
 what is the query to retrieve to student data based on least

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team