#include <iostream>
using namespace std;
int main()
{
int a[10], i, list;
cout << “Reading in: “;
for (i = 0; i<10; i++)
{
cin >> a[i];
cout << a[i];
cout << “, “;
// also tried cout<<arr[i]<<“,”; which did not work either an explanation as well please
How do I deal with removing the last comma after the array
Compare output nput 55 Reading in: 77, 33, 88, 99, 22, 55, 11, 44, 66,0 Enter a number from 0 t。9: 3 Element number 3 is 99 Reading in: 77, 33, 88, 99, 22, 55, 11, 44, 66, Enter a number from 0 to 9:3 Expected output Element number 3 is 99
Expert Answer
#include <iostream>
using namespace std;
int main()
{
int ar[10],n,num,no,i;
cout<<“Enter array element: “<<endl;
for(i=0;i<10;i++)
{
cin>>ar[i];
}
//Coding by: Snehil Khanor
//http://WapCPP.blogspot.com
cout<<“Reading in : “<<endl;
for(i=0;i<10;i++)
{
cout<<ar[i]<<“t”;
if(i==9)//when index will get valuee it will conntinue not print comma
continue;
cout<<“,”;
}
//////To search////
cout<<“nEnter number from o to 9: “;
cin>>num;
for(i=0;i<10;i++)
{
if(num==i)
{
cout<<“nElement number “<<num<<“is “<<ar[i];
no=0;
break;
}
else
{
no=1;
continue;
}
}
if(no==1)
cout<<“Sorry your search returned NO results. :(“;
return 0;
}