Title: Output an array in reverse order. 1. Program analysis: Swap the first with the last. 2. Program source code: #define N 5 main() { int a[N]={9,6,5,4,1},i,temp; printf(" original array: "); for(i=0;i for(i=0;i a[i]=a[Ni-1]; a[Ni-1]=temp; } printf(" sorted array: "); for(i=0;i } |
Title: There is an array that has been sorted. Now enter a number and insert it into the array according to the original rule. 1. Program analysis: First determine whether this number is greater than the last number, then consider the situation of inserting the middle number. After the insertion, the numbers after this element will be moved back one position in turn. 2. Program source code: main() { int a[11]={1,4,6,9,13,16,19,28,40,100}; int temp1,temp2,number,end,i,j; printf( "original array is: "); for ( i=0;i< 10;i++) printf ( "%5d",a[i]); printf(" " ) ; printf ( " insert a new number ; } } } for(i=0;i<11;i++) printf("%6d",a[i]); } |
Title: Find the sum of the diagonal elements of a 3*3 matrix 1. Program analysis: Use a double for loop to control the input of a two-dimensional array, and then add a[i][i] and output it. 2. Program source code: main() { float a[3][3],sum=0; int i,j; printf("please input rectangle element: "); for(i=0;i<3;i++) for(j=0;j<3;j++) scanf("%f",&a[i][j]); for(i=0;i<3;i++) sum=sum+a[i][i]; printf("duijiaoxian he is %6.2f",sum); } |
Title: Sort 10 numbers
1. Program analysis: You can use the selection method, that is, from the last 9 comparisons, select a smallest one and exchange it with the first element, and
then repeat the same process, that is, compare the second element with the last 8 and exchange them.
2. Program source code:
#define N 10
main()
{int i,j,min,tem,a[N];
/*input data*/
printf("please input ten num: ");
for(i=0;i
printf("a[%d]=",i);
scanf("%d",&a[i]);}
printf(" ");
for(i=0;i
printf(" ");
/*sort ten num*/
for(i=0;i
for(j=i+1;j
tem=a[i];
a[i]=a[min];
a[min]=tem;
}
/*output data*/
printf("After sorted ");
i=0;i
}
题目:求100之内的素数 1.程序分析: 2.程序源代码: #i nclude #i nclude "math.h" #define N 101 main() { int i,j,line,a[N]; for(i=2;i if(a[i]!=0&&a[j]!=0) if(a[j]%a[i]==0) a[j]=0;} printf(" "); for(i=2,line=0;i if(a[i]!=0) {printf("%5d",a[i]); line++;} if(line==10) {printf(" "); line=0;} } } |
Previous article:Design of relay drive system based on dual hot standby structure of AT90CAN128
Next article:Classic C Program (12/20)
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [#Ren Zhengfei responds to hot topics#: We cannot narrowly think that loving Huawei means loving Huawei phones]
- Here is the camera information on the national competition list
- RF Components Test Technology Seminar for 5G - You are invited to attend!
- Has anyone designed this power supply?
- Network Control of ROS Melodic
- Let’s take a look at how this overvoltage protection circuit can be optimized?
- Inverter and Motor Control
- 【ST NUCLEO-H743ZI Review】(2) First experience with Ethernet testing
- Disassembling a common fire emergency light
- [NXP Rapid IoT Review] Mobile APP connection finally succeeded