Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
同样的程序,同样的编译器,但我在c语言中得到了不同的输出 \\First程序 #包括 int main() { 整数数组[30],n,c,d,位置,交换; clrsc(); printf(“输入数组长度\n”); scanf(“%d”和“&n”); printf(“在数组中输入元素\n”); 对于(c=0;c_C - Fatal编程技术网

同样的程序,同样的编译器,但我在c语言中得到了不同的输出 \\First程序 #包括 int main() { 整数数组[30],n,c,d,位置,交换; clrsc(); printf(“输入数组长度\n”); scanf(“%d”和“&n”); printf(“在数组中输入元素\n”); 对于(c=0;c

同样的程序,同样的编译器,但我在c语言中得到了不同的输出 \\First程序 #包括 int main() { 整数数组[30],n,c,d,位置,交换; clrsc(); printf(“输入数组长度\n”); scanf(“%d”和“&n”); printf(“在数组中输入元素\n”); 对于(c=0;c,c,C,两个程序都是错误的,您会得到未定义的行为: \\First program #include<stdio.h> int main() { int array[30],n,c,d,position,swap; clrscr(); printf("Enter the legth of array\n"); scanf("%d",&n); printf("Enter element in array\n"); for(c=0;c<n;c++) { scanf("

两个程序都是错误的,您会得到未定义的行为:

\\First program
#include<stdio.h>
int main()
{
 int array[30],n,c,d,position,swap;
 clrscr();
 printf("Enter the legth of array\n");
 scanf("%d",&n);
 printf("Enter element in array\n");
 for(c=0;c<n;c++)
 { scanf("%d",&array[c]); }
 for(c=0;c<(n-1);c++)
 {
  position = c;
  for(d=c+1;d<n;d++)
  {
  if(array[position] > array[d])
  position = d;
  }
 if(position != c)
  { swap = array[c];
   array[c]= array[position];
   array[position] = swap;
  }
 }
printf("Sorted list\n");
for(c=0;c<n;c++);
{printf("%d\n",array[c]);}
getch();
}


\\Second program
#include<stdio.h>
#include<conio.h>
int main()
{
 int array[30],n,c,d,position,swap;
 clrscr();
 printf("Enter the legth of array\n");
 scanf("%d",&n);
 printf("Enter element in array\n");
 for(c=0;c<n;c++)
 { scanf("%d",&array[c]); }
 for(c=0;c<(n-1);c++)
 {
  position = c;
  for(d=c+1;d<n;d++)
  {
   if(array[position] > array[d])
   position = d;
  }
  if(position != c)
  { swap = array[c];
    array[c]= array[position];
    array[position] = swap;
  }
 }
 printf("Sorted list\n");
 for(c=0;c<n;c++);
 {printf("%d\n",array[c]);}
 getch();
 return 0; 
}

for(c=0;c“几乎相同”与“相同”-找出两者之间的差异,您可能会发现不同输出的原因。
#include
return 0;
是我使用工具发现的唯一差异。听起来像是未定义的行为。您可能有未初始化的变量和/或您访问数组超出了范围。
for(c=0;c<n;c++);  // << the ; should not be here
                   // now c contains 2
                   // and you print array[2] once
                   // and as array[2] hasn't bee initialized
                   // printf will print a more or less random value

{printf("%d\n",array[c]);}
getch();
for (c = 0; c < n;c++)
{
  printf("%d\n",array[c]);}
}
getch();