1
, there are 100 integers, which have negative numbers, to find the sum of the three consecutive numbers of the largest part.
Example:
Input: 2,-8, 3,-2, 4,-10
Output: 5 ({3,-2, 4})
#include <stdio.h>int?func_max (int?buf[],int?n)//Calculate the maximum value of the array and return the maximum value of the subscript {int?max=0;int?i;for (i=1;i<n-1;i++) if (Buf[i]>buf[max]) Max=i;return?max;} Void?func_sum (int?arr[],int?n)//number of consecutive three numbers and {int?buf[97]={0};//100 up to 97 consecutive added and Int?i=0;for (i=0;i<n-3;i++) buf[i ]=arr[i]+arr[i+1]+arr[i+2];int?index=func_max (buf,n-3);p rintf ("%d{%d,%d,%d}", Buf[i],arr[index],arr[index+1], ARR[INDEX+2]);} Int?main () {int?a[100]={0};p rintf ("Please?input?a?number:"); INT?I=0,N=0;SCANF ("%d", &n); for (i=0;i<n;i++) scanf ("%d", A[i]); Func_sum (a,n); return?0;}
2, Embedded systems often have features that require programmers to access a particular memory location. In a project, a value of 0xaa55 is required to set an integer variable with an absolute address of 0x67a9. The compiler is a purely ANSI compiler. Write the code to complete the task.
#include <stdio.h>int?main () {???? int?*ptr;???? Ptr?=? (int?*) 0x67a9;???? *ptr?=?0xaa55;???? return?0;?}
C Language Quiz 2