- 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(); }

27th Sep 2020, 6:27 AM
Bebi Yadav
Bebi Yadav - avatar
13 Respuestas
+ 6
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.
27th Sep 2020, 7:13 AM
Minho
Minho - avatar
+ 6
You code is working properly try other ide here getch () and conio.h headerfile not supporting so this will give errors here . If you want to run your code on solo then u have to remove these and give all input at a time otherwise it wont show any Output.
27th Sep 2020, 10:17 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Sorry curly bracket
27th Sep 2020, 6:57 AM
Bebi Yadav
Bebi Yadav - avatar
+ 1
I've asked what's problem in the code you given
27th Sep 2020, 6:52 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 1
I can't understand can you repeat in English
27th Sep 2020, 6:54 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 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
27th Sep 2020, 7:40 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 1
Ok thanks
27th Sep 2020, 8:21 AM
Bebi Yadav
Bebi Yadav - avatar
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.
27th Sep 2020, 6:49 AM
Bebi Yadav
Bebi Yadav - avatar
0
This is the question
27th Sep 2020, 6:49 AM
Bebi Yadav
Bebi Yadav - avatar
0
Error aa rhaa h
27th Sep 2020, 6:53 AM
Bebi Yadav
Bebi Yadav - avatar
0
Actually aap run kro dekho ptaa chal jayegaa
27th Sep 2020, 6:53 AM
Bebi Yadav
Bebi Yadav - avatar
0
Okk actually there is the r Error of parenthesis in the program
27th Sep 2020, 6:56 AM
Bebi Yadav
Bebi Yadav - avatar
0
hello
28th Sep 2020, 2:45 PM
مازیار رضایی
مازیار رضایی - avatar