fork download
  1. #include <stdio.h>
  2. #include<stdlib.h>//mallocを使うので足す
  3.  
  4. int main(void) {
  5. // your code goes here
  6. int n,i;
  7. int *x;
  8. scanf("%d",&n);//普通に文字を入力させる
  9. x=(int*)malloc(sizeof(int)*n);
  10. if(x==NULL){//エラー処理
  11. printf("ERROR\n");
  12. return 0;
  13. }
  14. for(i=0;i<n;i++){
  15. x[i]=i+1;//確定した領域にi+1を代入していく
  16. }
  17. for(i=0;i<n;i++){
  18. printf("%d ",x[i]);//代入したものを表示させる
  19. }
  20. free(x);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5296KB
stdin
4
stdout
1 2 3 4