C Language Quiz 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.