المحاضرة السادسة برمجة .محاضرة اليوم

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

‫المحاضرة السادسة‬

‫اكتب برنامج الضافة رقم الى مصفوفة احادية مع ازاحة رقم‬


#include <iostream>
using namespace std;
void addnumberToarray();
int main()
{
int array[5]={1,2,3,4,5},index,input;
cout<<"Enter The number to add:";
cin>>input;
cout<<"Enter The Location to add:";
cin>>index;
for(int i=5;i>=0;i--){
array[i+1]=array[i];

}
array[index]=input;
for(int j=0;j<6;j++){
cout<<array[j];

}
cout<<endl;
return 0;
}
_________________________________________________________
‫اكتب برنامج الستبدال رقم في مصوفة برقم مدخل‬
#include <iostream>
using namespace std;
void addnumberToarray();
int main()
{
int array[5]={1,2,3,4,5},newvalu,input;
bool isfound=false;
cout<<"Enter The number to add:";
cin>>input;
cout<<"Enter The Location to add:";
cin>>newvalu;
for(int i=0;i>=5;i++){
if(input==array[i]){

array[i]=newvalu;
isfound=true;
}
else
cout<<"The Number Is Not Found";

for(int j=0;j<6;j++){
cout<<array[j];

}
cout<<endl;
return 0;
}
______________________________________________________
‫اكتب برنامج لجمع عناصر القطر الثانوي لمصفوفة ثنائية البعد‬
#include <iostream>
using namespace std;
int main()
{
int a[3][3]={{5,6,2},{8,6,4},{3,1,7}};
int i,j,sum=0;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
if(i!=j && j>i)
// sum+=
a[i][j]=0;
cout<<a[i][j]<<endl;
}

return 0;
}
_______________________________________________________________

You might also like