51. Copy character array s2 s1 to all the characters in copying '\ 0' should be copied over, not copied later.
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char str1[20],str2[20];
gets(str2);
for(i=0; i<strlen(str2); i++)
str1[i]=str2[i];
puts(str1);
printf("\n");
return 0;
}
operation result:
52. Enter the number 10, wherein the maximum required output value of the number of elements and the number is the first number.
#include <stdio.h>
int main()
{
int max,maxi,i,a[10];
for(i=0; i<10; i++)
scanf("%d",&a[i]);
max=a[0];
maxi=0;
for(i=0; i<10; i++)
if(a[i]>max)
{
max=a[i];
maxi=i;
}
printf("其中值最大的元素为%d,为第%d个元素",max,maxi+1);
printf("\n");
return 0;
}
operation result:
53. recursion with
(i=1~100)
#include <stdio.h>
int f(int n)
{
if(n==1)
return 1;
else
return f(n-1)+n*n;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d",f(n));
printf("\n");
return 0;
}
operation result:
54. The one-dimensional array, putting up 10 student achievement, calculated the average score, the highest score, lowest score.
#include <stdio.h>
int main()
{
int a[10],max,min;
float sum=0;
for(int i=0; i<10; i++)
scanf("%d",&a[i]);
max=min=a[0];
for(int i=0; i<10; i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
sum+=a[i];
}
printf("Average=%.2f\nMax=%d\nMin=%d",sum/10.0,max,min);
printf("\n");
return 0;
}
operation result:
55. Write a function, the two-dimensional array (3 * 3) transposed, that the ranks of exchange
#include <stdio.h>
#define N 3
int main()
{
int i,j,a[N][N],temp;
for(i=0; i<N; i++) //输入原矩阵
for(j=0; j<N; j++)
scanf("%d",&a[i][j]);
printf("原矩阵为:\n");
for(i=0; i<N; i++) //输出原矩阵
{
for(j=0; j<N; j++)
printf("%d ",a[i][j]);
printf("\n");
}
for(i=0; i<N; i++) //转置矩阵
for(j=0; j<i; j++)
{
temp=a[i][j];
a[i][j]=a[j][i];
a[j][i]=temp;
}
printf("转置后得矩阵:\n");
for(i=0; i<N; i++) //输出转置后的矩阵
{
for(j=0; j<N; j++)
printf("%d ",a[i][j]);
printf("\n");
}
printf("\n");
return 0;
}
operation result:
56. The input character string in reverse order
#include <stdio.h>
#include <string.h>
int main()
{
int n;
char s,str[20];
gets(str);
n=strlen(str);
for(int i=0; i<n/2; i++)
{
s=str[i];
str[i]=str[n-i-1];
str[n-i-1]=s;
}
puts(str);
printf("\n");
return 0;
}
operation result:
57. Copy vowel string to another string, and then outputs
#include <stdio.h>
void fuzhi(char a[],char b[])
{
int i,j;
for(i=0,j=0; a[i]!='\0'; i++)
if(a[i]=='a'||a[i]=='o'||a[i]=='e'||a[i]=='i'||a[i]=='u'||a[i]=='A'||a[i]=='O'||a[i]=='E'||a[i]=='I'||a[i]=='U')
b[j++]=a[i];
b[j]='\0';
}
int main()
{
char a[20],b[20];
gets(a);
fuzhi(a,b);
puts(b);
printf("\n");
return 0;
}
operation result:
58. Enter a four-digit, four-digit output character, but with a space between each of the two numbers
#include <stdio.h>
int main()
{
int i,number;
scanf("%d",&number);
int a[4];
char s[4];
a[0]=number/1000;
a[1]=number/100%10;
a[2]=number%100/10;
a[3]=number%10;
for(i=0; i<4; i++)
{
s[i]=a[i]+48;
printf("%c ",s[i]);
}
printf("\n");
return 0;
}
operation result:
59. Enter a octal, decimal number corresponding output
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
char num[10];
int i,n,sum;
gets(num);
sum=0;
n=strlen(num);
for(i=n-1; i>=0; i--)
if(num[i]>='0'&&num[i]<='7')
sum+=(num[i]-'0')*pow(8,n-i-1);
printf("八进制:%s\n十进制:%d",num,sum);
printf("\n");
return 0;
}
operation result:
60. Enter a hexadecimal number, the decimal equivalent output
#include <stdio.h>
#include <string.h>
#include <math.h>
int ff(char shu[])
{
int i,n,sum;
n=strlen(shu);
sum=0;
for(i=n-1; i>=0; i--)
{
if(shu[i]>='0'&&shu[i]<='9')
sum+=(shu[i]-'0')*pow(16,n-i-1);
else if(shu[i]>='a'&&shu[i]<='f')
sum+=(shu[i]-'a'+10)*pow(16,n-i-1);
else if(shu[i]>='A'&&shu[i]<='F')
sum+=(shu[i]-'A'+10)*pow(16,n-i-1);
}
return sum;
}
int main()
{
char num[10];
gets(num);
int sum=ff(num);
printf("十六进制:%s\n十进制:%d",num,sum);
printf("\n");
return 0;
}
operation result: