Arama butonu
Bu konudaki kullanıcılar: 1 misafir
1
Cevap
477
Tıklama
0
Öne Çıkarma
c yardım plz. Çok basit (sanırım)
C
18 yıl
Onbaşı
Konu Sahibi

arkadaşlar aşağıdaki kodu yazıyorum label 3 de bir sorun var sıralanmış array ı yanlış yazdırıyor. Deli oldum lütfen yardım eder misiniz?
Bu şekilde hata alıyorum. Sondaki 3 tane fazladan olmayan rakam çıkıyo biryerlerden
Başka hata olmaması lazım ama bi incelerseniz çok sevinirim.
Tıkandım. Yardım edin lütfen.


< Resime gitmek için tıklayın >

 

/* Task: Write a program with a menu for choosing the next functions: */
/* a) Function enters an integer array P[k], k<25; */
/* b) Function that finds the elements, which belong to a define interval [a,b] and save them in a new array PN; */
/* c) Function that sorts this array (PN) descending. */

#include <iostream.h>
#include <conio.h>
int main()
{
int P[25],i,N,PN[25],j,tempi,temps,k=1,l=2,m=3,a,b,p,r,s;
/*First menu*/
label1:
cout<<"\n\t\tMenu";
cout<<"\n\t 1. Enter an array \n";
cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval (it needs 1st)\n";
cout<<"\t 3. Sort the new interval (it needs 1st and 2nd)\n";
cout<<"Your choise:";
cin>>k;
if(k>=1 && k<=3)
{
switch (k)
{
case 1: cout<<"\n\tYou have chosen 1. Enter an array";
do{cout<<"\n How many elements you have:";
cin>>N;}
while(N<1||N>25);
for(i=0;i<N;i++)
{cout<<"\n Input "<<i+1<<" number:";
cin>>P[i];}break;
case 2: cout<<"\nFirst you must enter the array\n";goto label1;break;
case 3: cout<<"\nFirst you must enter the array\n";goto label1;break;
}
}
else goto label1;
label2:
cout<<"\n\t\tMenu";
cout<<"\n\t 1. Enter an array (done)\n";
cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval\n";
cout<<"\t 3. Sort the new interval (it needs 2nd)\n";
cout<<"Your choise:";
cin>>l;
if(l>=1 && l<=3)
{
switch (l)
{
case 1: cout<<"\n\tYou have chosen 1. Enter an array but this has already done";
case 2: cout<<"\n\tStarting the next step\n";
cout<<"Enter the interval [a,b]";
cout<<"\na=";
cin>>a;
cout<<"\nb=";
cin>>b;
if(a>b)
{tempi=a;a=b;b=tempi;}
for(j=0,i=0;i<N;i++)
{
p=P[i];
if(p>a && p<b)
{PN[j]=P[i];j++;}
}
cout<<"\n New array:";
for(i=0;i<j;i++)
cout<<PN[i]<<" ";break;
case 3: cout<<"\nYou hadn't done the second step, yet.\n";goto label2;break;
}
}
else goto label2;
label3:
cout<<"\n\t\tMenu";
cout<<"\n\t 1. Enter an array (done)\n";
cout<<"\t 2. Enter interval and see the new array which \n\tbelong to the interval (done)\n";
cout<<"\t 3. Sort the new interval\n";
cout<<"Your choise:";
cin>>m;
if(m>=1 && m<=3)
{
switch (m)
{
case 1: cout<<"\n\tYou have chosen 1. Enter an array but this has already done";
case 2: cout<<"\n\tYou have chosen 2. Interval control but this has already done\n";
case 3: cout<<"\nStarting the next step\n";
for(s=0;s<i;s++)
for(r=s+1;r<i;r++)
if(PN[s]<PN[r])
{
temps=PN[s];
PN[s]=PN[r];
PN[r]=temps;
}
cout<<"\n Sorted Array: ";
for(i=0;i<N;i++)
cout<<PN[i]<<" ";
}
}
else goto label3;
cout<<"\nthe end";
getch();
return 0;
}

DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.

Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.

Üye Ol Şimdi Değil





< Bu mesaj bu kişi tarafından değiştirildi CAssassin -- 3 Kasım 2007; 4:44:54 >