سلام به شما دوستای خوبم،مخصوصا بچه های گروه کامپیوتر پیام نور سبزوار.
برنامه زیر یک آرایه nتایی را از ورودی دریافت نموده و با دریافت عددی از ورودی،اگر در آرایه موجود نباشد
آن را به آخر آرایه اضافه می کند.
برای دیدن کد برنامه به ادامه مطلب مراجعه کنید.
/*
سلام به شما دوستای خوبم،مخصوصا بچه های گروه کامپیوتر پیام نور سبزوار.
برنامه زیر یک آرایه nتایی را از ورودی دریافت نموده و با دریافت عددی از ورودی،اگر در آرایه موجود نباشد
آن را به آخر آرایه اضافه می کند.
*/
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#define MAX 1000
void main()
{
int array[MAX];
int i,n,x,found=0;
char ans='y',view='n';
textcolor(7);
textbackground(1);
clrscr();
cout<<"\n\n\tEnter number of data: ";
cin>>n;
int add=n;
for(i=0;i<n;i++)
{
cout<<"\n\tenter array["<<i<<"]= ";
cin>>array[i];
}
while (ans=='y')
{
found=0;
view='n';
clrscr();
cout<<"\n\n\tEnter a number for search/Add: ";
cin>>x;
for(i=0;i<add;i++)
if(array[i]==x)
found=1;
if(found==0 && add<MAX)
{
array[i]=x;
cout<<"\a\n\tThis Number Added...\n\t";
add++;
cout<<"\n\n\tdo you want View The Array?(y/n): ";
cin>>view;
}
else
cout<<"\a\n\tThis Number Exist in array!!!";
if(view=='y')
for(i=0;i<add;i++)
cout<<array[i]<<" ";
cout<<"\n\n\tdo you want continue?(y/n): ";
cin>>ans;
}
clrscr();
cout<<"\n\n\twww.Programist.blogsky.com";
delay(1800);
}