Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        5年前关闭。
                                                                                            
                
        
我正在开发一个程序,但目前它要求您输入值。

ex.

    How many number you want to enter?
    5

    Type in the numbers.
    1 2 3 4 5


但是我想预先定义一些数字,例如:


  int i [5] = {1,2,3,4,5}


怎么做?

这是代码。

#include <stdio.h>
#include <conio.h>

void main ()
{
 int number[30];
 int i,n,a,j;

 printf ("Enter the value of n\n");
 scanf ("%d",&n);

 printf ("Enter the numbers\n");
 for (i=0; i<n; ++i)
  scanf ("%d", &number[i]);

 printf ("Enter the position of the element to split the array \n");
 scanf ("%d",&a);

 for (i=0; i<a; ++i)
 {
  number[n] = number[0];

  for (j=0; j<n; ++j)
  {
   number[j] = number[j+1];
  }
 }

 printf("The resultant array is\n");
 for (i=0; i<n; ++i)
 {
  printf ("%d\n",number[i]);
 }
 getch();
}

最佳答案

#include <stdio.h>
#include <conio.h>

int main ()
{

  int number[5]={1,2,3,4,5};
  int i,n=5,a,j;
  printf ("Enter the position of the element to split the array \n");
  scanf ("%d",&a);

  for (i=0; i<a; ++i)
  {
    number[n] = number[0];

    for (j=0; j<n; ++j)
    {
      number[j] = number[j+1];
    }
  }

  printf("The resultant array is\n");
  for (i=0; i<n; ++i)
  {
    printf ("%d\n",number[i]);
  }
  getch();
  return 0;
}

关于c - 如何在我的C程序中定义开始索引? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27575678/

10-11 21:58
查看更多