nnpc.net
当前位置:首页 >> C语言,编写程序,使用指针求出一维整型数组,数组... >>

C语言,编写程序,使用指针求出一维整型数组,数组...

#include<stdio.h>#define ARRAY_LEN 100 int main(void) { int arr[ARRAY_LEN],len,i,*p=arr,*max=arr; printf("请输入初始数组元素个数:"); scanf("%d",&len); printf ("\n"); printf ("==========================================

#include<stdio.h>#define N 5 double addsum(float *p,int n) { int i; float *p1; double sum=0; p1=p; for(i=0;i<n;i++) { sum=sum + (*p1); p1++; } return(sum); } void main() { double product(float *p,int n); float a[N],*p; double sum; printf("input the number!

#include<stdio.h> int main() { int array[10]; int i, *p; for(p=array, i=0; i<10; i++) scanf("%d", p+i); for(p=array, i=0; i<10; i++) printf("%d ", *(p+i)); return 0; }

main() { int a[10],*p=a,i; for(i=0;i<10;i++) scanf("%d",p++); printf("\n"); for(i=0,p=a;i<10;i++) printf("%d\t",*p++); }

#include<stdio.h>#define N 10void main() { int a[N],i,*p; for ( i=0;i<N;i++ ) a[i]=i+1; p=a; p+=N-1; for ( i=0;i<N;i++,p-- ) printf("%d ",*p); printf("\n");}

#include#define N 8void main(){ int a[N],i,j,temp; int *p=a; printf("Please input an array including 8 numbles:"); for(i=0;i 评论0 0 0

#include#includevoid main(){ int len(int a[]); int *p,a[101]; for(p=a;p99) return i; return i-2;}

用两个知指针记录头和尾,道然后判断专奇数,偶数. void divideOddEven(int *arr, int n) { int *pHead = arr; int *pTail = (arr + n - 1); while (pHead<pTail) { if (*pHead % 2 == 1) pHead++; else if (*pHead % 2 !属= 1 && *pTail % 2 == 0) pTail--; else { swap(*pHead, *pTail); pHead++; } } }结果如下:

题目1 void main() { int i; char a[3];*a=1;*(a+1)=2;*(a+2)=3; for(i=0;i<3;i++) { printf("%d.\n",a[i]); } return; } 题目二#include<stdio.h> void main() { int i,j; int A[3][4]= { {1,2,3,4},{5,6,7,8},{9,10,11,12} }; int (*p)[4]=A; for(i=0;i<3;i++) { for(j=0;j<4;j++) { printf("%d.\n",*(*(p+i)+j)); } } return; }

#include <stdio.h> int iMax = 0; int fooMax(int arr[], int n) { int i; for (i = 0; i < n; i++) if (iMax < arr[i]) { iMax = arr[i]; } return iMax; } int main() { int arr[5] = { 10, 8, 15, 7, -1 }; printf("Max : %d\n", fooMax(arr, 5)); printf("Max : %d\n", iMax); return 0; }

网站首页 | 网站地图
All rights reserved Powered by www.nnpc.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com