# contains "stdafx.h"
int main(int argc,char* argv[])
{
int a[ 10]={ 1,3,5,7,9,8,6,4,2,0 }; //Initialize.
int b[ 10];
Printf ("sequential data: \ n");
for(int j = 0; j & lt 10; j++)
{
printf("%d ",a[j]);
printf(" ");
}
for(int I = 0; I< 10; i++)
{
b[ 10- 1-I]= a[I];
}
Printf ("\ nData after reverse order: \ n");
for(int n = 0; n & lt 10; n++)
{
printf("%d ",b[n]);
printf(" ");
}
Returns 0;
}
/*2, there is an integer array a[20]. First, enter a set of non-zero integers (less than 20) in the array, ending with the input value of 0. Write four functions to find 1, the number of positive numbers, 2, the average of positive numbers, 3, the number of negative numbers, 4 and the average of negative numbers of elements in the array, and finally enter four calculated values in the main function. Tip: Defining an array as: int a[20] actually only uses the first few elements of the array.
*/
# contains "stdafx.h"
int fun 1(int *ar,int num)
{
int au = 0;
for(int I = 0; I & ltnumi++)
{
if(ar[I]& gt; 0)
{
au++;
}
}
Printf ("positive number: %d\n", au);
Return to au;
}
Integer Function 2 (Integer * Integer, Integer)
{
int au = 0;
for(int I = 0; I & ltnumi++)
{
if(ar[I]& gt; 0)
{
au+= ar[I];
}
}
au=au/fun 1(ar,num);
Printf ("positive average: %d\n", au);
Return to au;
}
int fun3(int *ar,int num)
{
int au = 0;
for(int I = 0; I & ltnumi++)
{
if(ar[I]& lt; 0)
{
au++;
}
}
Printf ("negative number: %d\n", au);
Return to au;
}
Int fun4(int *ar, int number)
{
int au = 0;
for(int I = 0; I & ltnumi++)
{
if(ar[I]& lt; 0)
{
au+= ar[I];
}
}
au=au/fun 1(ar,num);
Printf ("negative average: %d\n", au);
Return to au;
}
int main(int argc,char* argv[])
{
int a[20];
Integer, date;
Printf ("Please enter data: \ n");
for(num = 0; num & lt20; num++)
{
Scanf("%d ",& date);
if(date==0)
{
Break;
}
Date;
}
fun2(a,num);
fun4(a,num);
Returns 0;
}
/*3. Enter a 4-digit number at will, store it in variable I, decompose the number on each digit of the number into integer array a[], arrange the numbers in array a[] in ascending order by selection method, and input the contents of array a[]. It is required to complete the selection sorting in the function.
Such as: int i, a [4]; Input i=8362
After decomposition: A [0] = 2, A [1] = 6, A [2] = 3, A [3] = 8.
After sorting: A [0] = 2, A [1] = 3, A [2] = 6, A [3] = 8.
At runtime, enter 8362.
Output 2368 */
# contains "stdafx.h"
Invalid funds (int *a, int num)
{
for(int I = 0; I< num-1; i++)
for(int j = I+ 1; j & ltnumj++)
{
if(a[I]& gt; a[j])
{
int date = a[I];
a[I]= a[j];
A[j]= date;
}
}
}
int main(int argc,char* argv[])
{
int I = 0;
int a[4];
Printf ("Please enter a four-digit integer: \ n");
scanf("%d ",& ampI);
for(int s= 1000,l = 0; l & lt4; s/= 10,l++)
{
a[l]= I/s;
I % = s;
}
Fun (a, 4);
for(int n = 0; n & lt4; n++)
{
printf("%d ",a[n]);
}
Returns 0;
}
4. Given the following two-dimensional array, find the sum of two diagonal elements in the array.
a=3 6 4 6
8 3 1 3
4 7 1 2
2 9 5 3
Requirements: 1, realized in the main function: the output of the initial value of the array and the sum result */
# contains "stdafx.h"
int main(int argc,char* argv[])
{
int a[4][4]={{3,6,4,6},{8,3, 1,3},{4,7, 1,2},{2,9,5,3 } };
int num = 0;
for(int i=0,j = 0; I<4; i++,j++)
{
num+= a[I][j];
}
Printf ("sum of the first diagonals:", num);
printf("%d\n ",num);
for(i=4- 1,j = 4- 1; I>0; I-,j-)
{
num+= a[I][j];
}
Printf ("sum of the second diagonals:", num);
printf("%d\n ",num);
Returns 0;
}
/*6, write a function viodmy _ strcpy (chars 1 [], chars2 []) to copy the string in s2 to the array s 1 Requirements:
1, the library function strcpy () in C language is not allowed.
2. Enter two strings in the main function, call the function my_strcpy () to copy the strings, and enter the contents of the strings S 1 and S2 in the main function.
Note: the character array s 1[] should be defined long enough to store concatenated strings */
# contains "stdafx.h"
void copystr(char *str 1,char *str2)
{
while(*str2)
{
* str 1++ = * str 2++;
}
}
int main(int argc,char* argv[])
{
Char st 1[]= "test string";
char st2[20]= " ";
copystr(st2,ST 1);
printf("%s\n ",st2);
Returns 0;
}
/*7, enter two strings, cross the corresponding letters to form the third string, and finally enter the third string. For example, the two input strings are "abcd" and "1234" respectively, and the merged string is "a 1b2c3d4". If the two strings are different in length, the redundant part of one string will be placed at the end of the result string. For example, the two strings are "banana" and "12" respectively, and the merged string is "b 1a2nana".
Requirement: The first letter of the first string is always the first letter of the result string.
*/
# contains "stdafx.h"
void combinstr(char *str 1,char *str2,char *str3)
{
for(; * str 1 | | * str 2; )
{
if(*str 1)
{
* str 3++ = * str 1++;
}
if(*str2)
{
* str 3++ = * str 2++;
}
}
}
int main(int argc,char* argv[])
{
char ST 1[]= " abcdefghi ";
char st2[]= " 1234 ";
char st3[64]= " ";
combinstr(st 1,st2,st3);
printf("%s\n ",st3);
Returns 0;
}
Only the fifth one is missing. How do you want to demonstrate?
Forget it, just get something that can see the effect: /*5, five students in three grades know it.
Course 1 Course 2 Course 3 Average
STUD 1 76 80 90
Student 2 90 65 77
Student 3 63 55 70
Student 4 90 92 97
Student 5 73 69 82
Requirements: 1, find and enter the average score of each student.
2. Find and enter the average score of each course.
*/
# contains "stdafx.h"
int main(int argc,char* argv[])
{
Floating studs [5][3]={{76, 80, 90}, {90, 65, 77}, {63, 55, 70}, {90, 92, 97}, {73, 69, 82}};
Floating point number = 0;
for(int I = 0; I<5; i++)
{
for(int j = 0; j & lt3; j++)
{
num+= stud[I][j];
}
num/= 3;
Printf(" \n% d Average grade of students: \ n ",I+1);
printf("%f\n ",num);
num = 0;
}
for(I = 0; I<3; i++)
{
for(int j = 0; j & lt5; j++)
{
num+= stud[I][j];
}
num/= 5;
Printf(" \ n Average grade is %d: \n ",I+1);
printf("%f\n ",num);
num = 0;
}
Returns 0;
}