Uploaded by Furqan Rathore

array assignment

advertisement
#include<iostream>
using namespace std;
int main()
{
int i, a[10] = { 25, 13, 45, 67, 34, 11, 23, 17, 20 }, no, pos;
cout << "\nStored Data in Array :: \n\n";
for (i = 0; i<10; i++)
{
cout << " " << a[i] << " ";
}
cout << "\n\nEnter position to insert number :: ";
cin >> pos;
if (pos>a[i])
{
cout << "\nEnter number to be inserted :: ";
cin >> no;
--pos;
for (i = a[i]; i >= pos; i--)
{
a[i + 1] = a[i];
}
a[pos] = no;
cout << "\nNew Array is :: \n\n";
for (i = 0; i<a[i] + 1; i++)
{
cout << " " << a[i] << " ";
}
}
cout << "\n";
cout << "-----after deletion-----\n";
for (int k = 0; k < 5; k++){
cout << " ";
cout << a[k];
}
for (int j = 5; j < 8; j++){
cout << " ";
a[j] = a[j + 1];
cout << a[j];
}
cout << endl;
system("pause");
}
#include "iostream"
using namespace std;
void main(){
int arr[5] = { 1, 2, 3, 4, 5 };
cout << "-----Normal output-----\n";
for (int i = 0; i <5; i++){
cout << arr[i] << endl;
}
cout << "-----Reverse output-----\n";
for (int i = (5 - 1); i >= 0; i--){
cout << arr[i] << endl;
}
system("pause");
}
Download