Write prgm to store the Element in 1 d array and perform operation like searching and traversing | SoloLearn: Learn to code for FREE!

+1

Write prgm to store the Element in 1 d array and perform operation like searching and traversing

#include<iostream.h> #include<conio.h> void main(); { int arr[10],search_ele,n,i,flag=-1; char ch; clrscr(); cout<"enter the size of array: "; cin>>n; cout<<"enter the element in array: "<<endl; for(i=0;i<n;i++) { cin>>arr[i]; } cout<<"\nenter 's' for searching element in array: "; cout<<"\nenter 't' for traversing element of array: "<<endl; cin>>ch; switch(ch) { case 's': cout<<"\nenter element to be seach: "; cin>>search_ele; for(i=0;i<n;i++) { if(arr[i]==search_ele) { flag=1; break; } else { flag=-1; } } if(flag==1) { cout<<"element "<<search_ele<<"found at index"<<i<<endl; } else { cout<<"element is not found in an array!"<<endl; break; } case 't': cout<<"\nTraverse of an array:"<<endl; for(i=0;i<n;i++) { cout<<"arr["<<i<<"]="<<arr[i]<<endl; } } getch(); }

c++

9/27/2020 6:27:37 AM

Bebi Yadav

13 Answers

New Answer

+5

Bebi Yadav Your code works fine. Just, Remove semi-colon after main() function. Also here in code playground you can neither use conio header file nor you can take multiple inputs.

+2

Sorry curly bracket

+1

I've asked what's problem in the code you given

+1

I can't understand can you repeat in English

+1

Corrections: 1. In header .h not required for iostream. 2. Remove semicolon in main function 3. Added Curly braces after case statement. Because there are multiple statements in case. Bebi Yadav Check now : https://code.sololearn.com/cUOg1hPzekMQ/?ref=app

+1

Ok thanks

0

2.Write a Menu Driven program to store the elements in 1-D array and perform the operations like searching and reversing the elements.

0

This is the question

0

Error aa rhaa h

0

Actually aap run kro dekho ptaa chal jayegaa

0

Okk actually there is the r Error of parenthesis in the program

0