三道C语言题目

2024-12-21 09:05:39
推荐回答(3个)
回答1:

1、
#include
#include
int main(int argc, char *argv[])
{
char a[ 100 ];
int count = 0, i = 0;
gets( a );
while( a[ i ] )
{
if(isdigit( a[ i ++ ] ))
count ++ ;
}
printf("%d\n",count);
return 0;
}

2、
#include
int main(int argc, char *argv[])
{
int i, j ;
int n;
double x ,max , min ,s = 0 ;
for(scanf("%d",&n) , i = 0 ; i < n ; i ++ )
{

scanf("%lf",&x);
if(!i)max = min = x;
else
{
if(x > max) max = x ;
if(x < min) min = x ;

}
s += x;
}
printf("%.2lf\n",( s - max - min) / (n - 2));
return 0;
}

3、
#include
int main(int argc, char *argv[])
{
int i , j , m , n ;
int a[100][100];
int max , max_x , max_y;
while(scanf("%d%d",&m,&n) != EOF)
{
for(i = 0 ; i < m ; i ++ )
{
for(j = 0 ; j < n ; j ++ )
{
scanf("%d",&a[ i ][ j ]);
if(!i && !j)
{
max = a[ i ][ j ];
max_x = max_y = 0;
}
else
{
if(abs( a[ i ][ j ] ) >= abs( max ))
{
max = a[ i ][ j ];
max_x = i;
max_y = j;
}
}
}
}
printf("%d %d %d\n" , max_x + 1 , max_y + 1 , max );
}
return 0;
}

回答2:

1.
#include
using namespace std;
int main()
{ char s[100];
int i,c=0;
gets(s);
for( i=0;i if(s[i]<='9'&&s[i]>='0')
c++;
cout<
}

2.
#include
#include
using namespace std;
int main()
{ int i,n,k,a[105],s=0;
cin>>n;
k=n;
while(n--)
cin>>a[n];
sort(a,a+k);
for(i=1;i s+=a[i];
cout< return 0;
}

3.
#include
#include
using namespace std;
const int M=100;
int main()
{ long a[M][M],i,j,m,n;
while(cin>>n>>m)
{ int max=0,k,t;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
cin>>a[i][j];
for(i=n;i>=1;i--)
for(j=m;j>=1;j--)
if(abs(max)<=abs(a[i][j]))
{ max=a[i][j];
k=i;t=j;
}
cout< }
return 0;
}

希望采纳!!!!

回答3:

#include
int countdigit(int number,int digit)
{
int count=0;
while(number!=0)
{
if(number%10==digit)count++;
number/=10;
}
return count;
}
main()
{
int number,digit;
scanf("%d%d",&number,&digit);
printf("%d\n",countdigit(number,digit));
}