2832: 使用指針訪問數組元素--程序填空

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1415  Solved: 727
[Submit][Status][Web Board]

Description

輸入10個整數值到數組中,使用指針來完成對這10個數組元素的逆向輸出。
 
在下面代碼的基礎上完成,提交時只提交begin之後和//end之前的代碼
 /*C++*/
#include <iostream>
using namespace std;
int main()
{
   int a[10];
   int *p;
   p=a;
   int i;
   for(i=0;i<10;i++)    //begin
      cin>>         
   //逆序輸出數組元素 
   for(           ;            ;              )     //end 
        cout<<*p<< " ";
 
  return 0;
}
/*C語言*/
#include<stdio.h>

int main()
{
   int a[10];
   int *p;  
   int i;
   p=a;
   for(i=0;i<10;i++)    //begin
      scanf( );
   //逆序輸出數組元素
   for(           ;            ;              )     //end
        printf("%d ",*p);

  return 0;
}

Input

10個整數

Output

這10個整數的逆向輸出

Sample Input

0 1 2 3 4 5 6 7 8 9

Sample Output

9 8 7 6 5 4 3 2 1 0 

HINT

合理的使用指針來完成對數組元素的訪問


提交時只提交begin之後和//end之前的代碼

Source

gyy



C語言代碼:

#include<stdio.h>


 int main()
 {
    int a[10];
    int *p;  


   int i;
    p=a;
    for(i=0;i<10;i++)    //begin
       scanf("%d",&p[i]);
    //逆序輸出數組元素
   for(i=9,p=p+i;i>=0;i--,p--)     //end 
         printf("%d ",*p);


   return 0;
 }


c++代碼:

#include <iostream>
using namespace std;
int main()
{
   int a[10];
   int *p;
   p=a;
   int i;
   for(i=0;i<10;i++)    //begin
      cin>>p[i]; 
   //逆序輸出數組元素 
   for(i=9,p=p+i;i>=0;p--,i--)     //end 
        cout<<*p<<" ";
  return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章