In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you the content of an example analysis of the algorithm of one-dimensional array in C language. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Problem 1: store the numbers in the array in reverse order
This problem requires writing a program to store the given n integers in the array, store the n numbers in the array in reverse order, and then output the elements in the array sequentially.
Algorithm description: 1. Enter elements into array a
two。 Define a new array new to store the elements in array an in reverse order
3. Output the array b in positive order and pay attention to the format with no spaces at the end.
Code implementation:
# include int main () {int n; scanf ("% d", & n); int iMagneur arr [n]; for (I = 0polii)
< n;i++) { scanf("%d",&arr[i]); } int new[n],j; //定义一个数组new用来存入数组a的逆顺序 for(int j = 0;j < n;j++) { new[j] = arr[n-1-i]; //倒序存入 } for(int k = 0;k < n - 1;k++) //数组中最后一个元素不一起输入,保持结尾无空格 { printf("%d ",new[k]); } printf("%d",new[n-1]); //输出最后一个元素 return 0;} 运行结果:Problem 2: find the maximum in the array and its subscript
This question requires a program to find out the maximum of a given number of n and its corresponding minimum subscript (the subscript starts at 0). Input format: enter a positive integer n (1 = I) {printf ("% d", rem [I]) in the first line / / because the first element is output ahead of time, you have to type the element with a space and then type the element. / / the format problem without spaces}} return 0;}
Running result:
Question 4: find out the number that occurs the most
This question requires statistics of the integers with the largest number of occurrences in an integer sequence and their occurrence times.
Input format: enter the number of integers N (0 end) / / given in the sequence on one line, consider special circumstances, if the number inserted is greater than the penultimate {arr [n] = num; / / directly insert assignment} else {for (I = 0 / I)
< n;i++) { if(arr[i] >Num) / / if the original number is greater than the inserted number {T1 = arr [I]; / / first save the original number arr [I] = num; / / put the inserted number to the position of the original number for (j = I + 1x j)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.