# 1-16 Jobs

Source: Internet
Author: User

"No. 04: one-dimensional array"

1. (*) Debug First, copy the following procedures after successful commissioning: #include <stdio.h>
#define SIZE 10
int main (int argc, char *argv[])

{
int A[size] = {0},i= 0;

for (i = 0; i < SIZE; i++) {a[i] = i+10;

printf ("a[%d] =%d\n", I, A[i]);}

return 0;}

2. (*) reverse the output of array A in the first question.

3. (*) sum the array in the first question and print the result of the calculation. 4. (* *) Calculate the first question array to reduce, print the calculation results.

5. (* *) randomly generated 20 10~50 positive integers stored in the array, and the array of the maximum number of elements, the minimum value, the mean and the sum of the elements.

6. Write a program, enter two arrays containing 5 elements, sort the two arrays in ascending order, and then merge the two arrays into an ascending array.

7. (* * *) Given a certain month of the year, the output is the day of the year.
8. (* *) write integer value array sequencer (bubble sort, select sort, quick sort-ascending)

int a[] = {3,-9,32,77,63,-24,14,0,21,45};9, (* * *) find the maximum and minimum values in the following integer array and where I is located.

int a[] = {5,-9,32,77,64,-24,14,0,21,45};

10, (*) Merge str1, str2, str3 into the result array. Char result[50] = {0};
Char str1[] = "Lanou";
Char str2[] = "23_class";

Char str3[] = "is Niu best!"; Result: "Lanou 23_class is Niu best!"

11, (* *) to find the following program error:

int main (int argc, char *argv[]) {

Char string[10], str1[10]; int i;
for (i = 0; i <; i++)
{

Str1[i] = ' a ';}

strcpy (string, str1);}

12, (* *) The following program will be executed after the error or effect: int main (int argc, char *argv[])
{

unsigned char str[10], i;for (i = 0; i < i++) str[i] = i;

}

//

Main.m

4th Lecture: one-dimensional arrays

//

Created by Lanouhn on 15/1/16.

//

#import <Foundation/Foundation.h>

#define SIZE 10

int main (int argc, const char * argv[]) {

1.

int A[size] = {0}, i = 0;

for (i = 0; i < SIZE; i++) {

A[i] = i + 10;

printf ("a[%d] =%d\n", I, a[i]);

//    }

2.

int A[size] = {0};

for (int i = SIZE-1; I >= 0; i--) {

A[i] = i + 10;

printf ("a[%d] =%d\n", I, a[i]);

//    }

printf ("\ n");

3.

int A[size] = {0}, i = 0, sum = 0;

for (i = 0; i < SIZE; i++) {

A[i] = i + 10;

sum = sum + a[i];

printf ("a[%d] =%d\n", I, a[i]);

//    }

printf ("sum =%d\n", sum);

4.

int A[size] = {0}, i = 0, sub = 0;

for (i = 0; i < SIZE; i++) {

A[i] = i + 10;

Sub = Sub-a[i];

printf ("a[%d] =%d\n", I, a[i]);

//    }

Sub = sub + a[0];

printf ("Sub =%d\n", sub);

5.

int a[20] = {0}, sum = 0, max = 0, min = 0;

float avg = 0.0;

for (int i = 0; i <; i++) {

A[i] = arc4random ()% 41 + 10;

sum = sum + a[i];

printf ("a[%d] =%d", I, a[i]);

//        }

AVG = SUM/20;

printf ("\ n");

for (int i = 0; i < 20-1; i++) {

for (int j = 0; J < 20-1-I; j + +) {

if (A[j] > a[j + 1]) {

int x = A[j];

A[J] = a[j + 1];

A[j + 1] = x;

//            }

//        }

//    }

printf ("max =%d\nmin =%d\navg =%.2f\nsum =%d\n", a[20-1], a[0], AVG, sum);

6.

int a[5] = {0}, B[5] = {0};

printf ("Please enter five numbers for array A:"),

scanf ("%d%d%d%d", &a[0], &a[1], &a[2], &a[3], &a[4]);

printf ("Please enter five numbers for array B:");

scanf ("%d%d%d%d", &b[0], &b[1], &b[2], &b[3], &b[4]);

for (int i = 0; i < 5-1; i++) {

for (int j = 0; J < 5-1-I; j + +) {

if (A[j] > a[j + 1]) {

int x = A[j];

A[J] = a[j + 1];

A[j +1] = x;

//                }

if (B[j] > b[j + 1]) {

int y = b[j];

B[J] = b[j + 1];

B[j + 1] = y;

//            }

//        }

//    }

for (int i = 0; i < 5; i++) {

printf ("a[%d] =%d b[%d] =%d\n", I, a[i], I, b[i]);

//    }

int c[10] = {0};

for (int k = 0,i = 0,j = 0; k <; k++) {

if (i = = 5) {C[k] = B[j]; j + +;}

else if (j = = 5) {C[k] = a[i]; i++;}

else if (A[i] > B[j]) {c[k] = B[j]; j + +;}

else {C[k] = a[i]; i++;}

//    }

//

for (int o = 0; o < o++) {

printf ("c[%d] =%d\n", O, C[o]);

//    }

7.

int year = 0, mouth = 0,day = 0, days = 0, a = 0;

scanf ("%d%d%d", &year, &mouth, &day);

If (year% 400 = = 0 | | (year% 4 = = 0 && Year% 100! = 0)) {

A = 1;

} else {

A = 0;

//    }

if (a = = 1) {

int a[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

for (int i = 0;i < mouth-1; i++) {

Days = days + a[i] + 1;

//            }

Days = days + day;

} else if (a = = 0) {

if (Mouth > 2) {

int a[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

for (int i = 0;i < mouth-1; i++) {

Days = days + a[i] + 1;

//        }

//        }

//    }

printf ("The year is%d of the year \ n", days);

//

//

//

8.

int a[] ={3,-9, 32, 77, 63,-24, 14, 0, 21, 45};

for (int i = 0; i < 10-1; i++) {

for (int j = 0; J < 10-1-I; j + +) {

if (A[j] > a[j + 1]) {

int temp = A[j];

A[J] = a[j + 1];

A[j + 1] = temp;

//            }

//        }

//    }

for (int i = 0; i < i++) {

printf ("a[%d] =%d", I, a[i]);

//    }

printf ("\ n");

9.

int a[] ={3,-9, 32, 77, 63,-24, 14, 0, 21, 45};

int b[10] = {0};

for (int i = 0; i < i++) {

B[i] = A[i];

printf ("b[%d] =%d", I, b[i]);

//    }

for (int i = 0; i < 10-1; i++) {

for (int j = 0; J < 10-1-I; j + +) {

if (A[j] > a[j + 1]) {

int temp = A[j];

A[J] = a[j + 1];

A[j + 1] = temp;

//            }

//        }

//    }

//

printf ("\ n");

for (int i = 0; i < i++) {

if (b[i] = = A[0]) {

printf ("Minimum value is a[%d", the number of%d in the array is \ n ", I, i + 1);

//        }

if (b[i] = = A[9]) {

printf ("Maximum value is a[%d", in the array is the number of%d \ n ", I, i + 1);

//        }

//    }

10.

Char result[50] = {0};

Char str1[] = "Lanou";

Char str2[] = "18_class";

Char str3[] = "are NIU best";

strcat (result, str1);

strcat (result, str2);

strcat (result, STR3);

printf ("result[50] =%s\n", result);

11.

Char string[10], str1[10];

int i;

for (i = 0; i <; i++)

//    {

Str1[i] = ' a '; }

strcpy (string, str1);

printf ("string[10] =%s\n", string);

printf ("str1[10] =%s\n", str1);

//

12.

unsigned char str[10];

int i;

for (i = 0; i < i++) {

Str[i] = i;

//    }

printf ("str[10] =%s", str);

//

//

return 0;

}

1-16 Jobs

Related Keywords:

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.