要点:
小写字母转大写字母
if(‘a’ < tt[i] && tt[i] > ‘z’ )
tt[i] -= 32;
详细代码如下:
#include <stdio.h>
#include <string.h>
char* fun( char tt[] )
{
int i;
for( i = 0; tt[i]; i++ )
/**********found***********/
if(( 'a' <= tt[i] )&&( tt[i] <= 'z' ) )
/**********found***********/
tt[i] -= 32;
return( tt );
}
void main( )
{
char tt[81];
printf( "\nPlease enter a string: " );
gets( tt );
printf( "\nThe result string is:\n%s", fun( tt ) );
}
要点:
判断非素数
详细代码如下:
#include <stdio.h>
void fun( int m, int *k, int xx[] )
{
/*
analyse:
大于1 小于整数m
的非负数:
*/
int i, j, n = 0;
for(i = 4; i < m; i++)
{
for(j =2; j<i; j++)
{
if(i%j == 0) //不是素数
break;
}
if(j<i)
xx[n++] = i;
}
*k = n;
/* ERROR:
int i,j,w =0;
for(i = 2; i < m; i++)
{
//判断非素数
for(j = 2; j < m; j++)
if(i%j !=0 )
{
xx[w++]= i;
}
}
*k =w;
*/
}
void main()
{
int m, n, zz[100];
void NONO ( );
printf( "\nPlease enter an integer number between 10 and 100: " );
scanf( "%d", &n );
fun( n, &m, zz );
printf( "\n\nThere are %d non-prime numbers less than %d:", m, n );
for( n = 0; n < m; n++ )
printf( "\n %4d", zz[n] );
NONO();
}