Advertisement
hamaXD

อีเปียว

Oct 4th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include<stdio.h>
  2. #define NUM 5
  3. int* max(int* a, int *b);
  4. int sum(int *p, int *q);
  5. int main(){
  6.     int i, a[NUM],*x;
  7.     for(i = 0; i < NUM; i++){
  8.         printf("N%02d:", i + 1);
  9.         scanf("%d", &a[i]);
  10.     }
  11.     printf("=%d\n", sum(&a[0], &a[NUM]));
  12.     x=max(&a[0], &a[NUM]);
  13.     printf("=%d\n",*x);
  14.     return 0;
  15. }
  16. int sum(int *p, int *q){
  17.     int i=0,temp=0;
  18.     for(i=0;i<NUM;i++){
  19.         if(*(p+i)!=*q){
  20.             temp+=*(p+i);
  21.         }
  22.     }
  23.     return temp;
  24. }
  25. int* max(int* a, int *b){
  26. int temp[NUM],i,tmp,j;
  27.     for (i = 0; i < NUM; i++){
  28.         for (j = 0; j < (NUM - i - 1); j++){
  29.             if (*(a+j) <*(a+(j+1))){
  30.                 tmp = *(a+j);
  31.                 *(a+j) = *(a+(j+1));
  32.                 *(a+(j+1)) = tmp;
  33.             }
  34.         }
  35.     }
  36.     return a;  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement