Internal algorithm (character c)
{
if((c & gt; = ' a ' & amp& ampc & lt= ' z ')| |(c & gt; = ' A ' & amp& ampc & lt='Z '))
Returns (1);
other
return(0); /* Find 1 */
}
int longest(char * str)//int longest(char str)
{
int len=0,I,length=0,flag= 1,point,place
for(I = 0; I<= strlen(str);); i++)
if(alph(str[i]))
If (logo)
{
flag = 0;
Point = I;;
}
other
len++;
else /* Find 2 */
{
flag = 1; //flag = 0;
if(len & gt; Length)
{ length = len
place = point
len = 0; }
}
To return to (a place);
}
Master ()
{
int I;
Char line [100];
Printf ("input string \ n");
Get (line);
Printf ("The longest is:");
For(I = longest (line); Alph (line [i]); i++)
Printf("%c ",line [i]);
printf(" \ n ");
}
Second, fill in the blanks by procedures
Tk22.c is to print Yang Hui triangle, complete the program in the blank, and get the correct result after running.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
.
.
.
# Definition number 1 1
Master ()
{
int I,j,a[N][N];
for(I = 1; I & ltn;; I++)
{ a[I][I]= 1;
a[I][ 1]= 1; //
}
for(I = 3; I & ltn;; I++)
for(j = 2; J< me; j++ )//
a[I][j]= a[I- 1][j- 1]+a[I- 1][j];
for(I = 1; I & ltn;; I++)
{ for(j = 1; j & lt= I; j++)
printf("%6d ",a[I][j]);
printf(" \ n ");
}
printf(" \ n ");
}
1. Program error correction (20 points).
The following process is to establish a one-way linked list containing student-related data. However, there are two errors in this program that appear near each comment line. Please debug and correct them. During debugging and correction, the program structure shall not be changed, and statements shall not be added or deleted.
# Define NULL 0
Structural stud
{
Long num
Character name [10];
Floating score;
struct stud * next
};
/* ..................... */
int n;
Structural Stud Creation ()
{
Structural stud * head, *p 1, * p2
n = 0;
P 1=p2= (structural stud *)malloc(sizeof);
scanf("%ld,%s,%f ",& ampp 1->; num,p 1->; Name & amp1->; Score);
/* ..................... */
head = NULL
And (p 1! =0)
{
n = n+ 1;
if(n = = 1)head = p 1;
Otherwise p2-& gt;; next = p 1;
P 1= (structural stud *)malloc (size (structural stud));
scanf("%ld,%s,%f ",& ampp 1->; num,p 1->; Name & amp1->; Score);
}
p2->; next = NULL
Return (head);
}
2. Fill in the blanks (20 points).
The following program is to input several lines of character strings with different lengths from the keyboard and save them in a disk file named ttt.txt, then output these data from the file to the screen, and convert lowercase letters into uppercase letters. However, this program is an incomplete program. Please complete in the underlined space to get the correct answer, but do not add or delete the original sentence.
# include & ltstdio.h & gt
Master ()
{
int i,flag
String [80], c;
FILE * fp
if((fp=fopen("TTT "," w"))==NULL)
{printf ("Unable to create file \ n");
Exit (0);
}
for(flat = 1; Flag; )
{printf ("Please enter a string \ n");
gets(str);
fprintf(fp," %s ",str);
Printf ("Do you want to continue typing? \ n ");
if((c=getchar()=='N'|| ( 1))
flag = 0;
getchar();
}
fseek(fp,0,0);
while(fscanf(fp," %s ",str)! =EOF)
{ for(I = 0; str[i]! ='\0'; i++)
if((str[I]& gt; = ' a ' & amp& amp(str[I]& lt; ='z '))
str[i]=_(2)
printf("%s ",str);
}
fclose(FP);
}
Test 1. Program revision:
The gc56.c program is used to convert lowercase letters in a string into uppercase letters. There are two errors in the program. Please debug and correct them.
Yes, but you can't add or delete any statements.
# include & ltstdio.h & gt
Invalid master (invalid)
{
char s[255];
int I;
scanf("%s ",s);
for(I = 0; s[I]; i++)
if(s[I]& gt; = ' a ' & amp& amps[I]& lt; = ' z ')//if(s[I]& gt; = ' b ' & amp& amps[I]& lt; ='z ')
s[I]= s[I]-' A '+' A '; //s[I]= s[I]+' A '+' A ';
printf("%s ",s);
}
Question 2: Fill in the blanks according to the procedure.
Tk56.c program is used to calculate the position of the row and column of the largest element in a 4×5 integer array. The following procedures are incomplete,
Please fill in the blanks in order to get the correct answer. Note: You cannot add or delete rows or modify the structure of the program. .
# include & ltstdio.h & gt
Invalid master (invalid)
{
int a[4][5]={{4,8,9, 10, 12},
{2,5, 13, 17, 1 1},
{8 1,76,34,57,33},
{ 1,90,3,78,55}};
int max,max_row,max _ col
int i,j;
max = a[0][0]; //
max _ row = 0;
max _ col = 0;
for(I = 0; I<4; i++)
for(j = 0; j & lt5; j++)
if(max & lt; a[I][j]//
{
max = a[I][j];
max _ row = I;
max _ col = j;
}
printf("%d %d ",max_row,max _ col);
}
Test 1. Program revision:
The gc56.c program is used to convert lowercase letters in a string into uppercase letters. There are two errors in the program. Please debug and correct them.
Yes, but you can't add or delete any statements.
# include & ltstdio.h & gt
Invalid master (invalid)
{
char s[255];
int I;
scanf("%s ",s);
for(I = 0; s[I]; i++)
if(s[I]& gt; = ' a ' & amp& amps[I]& lt; = ' z ')//if(s[I]& gt; = ' b ' & amp& amps[I]& lt; ='z ')
s[I]= s[I]-' A '+' A '; //s[I]= s[I]+' A '+' A ';
printf("%s ",s);
}
Question 2: Fill in the blanks according to the procedure.
Tk56.c program is used to calculate the position of the row and column of the largest element in a 4×5 integer array. The following procedures are incomplete,
Please fill in the blanks in order to get the correct answer. Note: You cannot add or delete rows or modify the structure of the program. .
# include & ltstdio.h & gt
Invalid master (invalid)
{
int a[4][5]={{4,8,9, 10, 12},
{2,5, 13, 17, 1 1},
{8 1,76,34,57,33},
{ 1,90,3,78,55}};
int max,max_row,max _ col
int i,j;
max = a[0][0]; //
max _ row = 0;
max _ col = 0;
for(I = 0; I<4; i++)
for(j = 0; j & lt5; j++)
if(max & lt; a[I][j]//
{
max = a[I][j];
max _ row = I;
max _ col = j;
}
printf("%d %d ",max_row,max _ col);
}
2. Program error correction
The function of gc57.c is to exchange the maximum and minimum numbers in a given array. For example, the following eight numbers:
5,3, 1,4,2,8,9,6
Become:
5,3,9,4,2,8, 1,6
In the program, the exchange operation between the maximum number and the minimum number is realized by function call, so that the pointers max and min point to the maximum number and the minimum number respectively. There are two errors in the program, please correct them. Note: You cannot add or delete rows or modify the structure of the program.
Master ()
{
int I;
static int a[8]={5,3, 1,4,2,8,9,6 };
void jhmaxmin();
Printf ("original array: \ n");
for(I = 0; I<8; i++)
printf("%5d ",a[I]);
printf(" \ n ");
jhmaxmin(a,8);
Printf ("array after exchanging max and min: \ n");
for(I = 0; I<8; i++)
printf("%5d ",a[I]);
printf(" \ n ");
}
void jhmaxmin(p,n)
int *p,n; //int p,n;
{
int t、*max、*min、*end、* q;
end = p+n;
max = min = p;
for(q = p+ 1; Q< is over; q++)
{ if(* q & gt; * max)max = q;
if(* q & lt; * min)min = q; //if(* q & lt; max)min = q;
}
t = * max* max = * min* min = t;
}
1. Fill in the blanks according to the procedure.
Tk57.c is used to output all prime numbers (prime numbers) between two integers m and n. An integer n is a prime number, which means that n can be divisible by 1 and its own n.
, not divisible by any integer between 2 and n- 1. For example, 7 is a prime number and 9 is not.
In the program, the outer loop variable I is used to control the range of integer selection, and the inner loop variable J is used to judge whether an integer I is a prime number. If so,
Output prime numbers, and the output of 5 prime numbers per line is controlled by variable S. ..
# Define M 4
# Define N 30
Master ()
{
int i,j,k,s = 0;
for(I = M; I < = n; i++)//
{ for(j = 2; J< me; j++)//
If(i%j== 0) interrupt;
if(j & gt; =i)
{ printf("%5d ",I);
s = s+ 1;
if(s % 5 = = 0)printf(" \ n ");
}
}
printf(" \ n ");
}
Program error correction problem:
The function of gc 10 1.c is to input 8 integers and sort them by selection method (from small to large). There are three error codes in the program, please correct them. Please note that the program structure must not be changed.
# include & ltstdio.h & gt
Master ()
{
int a[8],* p = a;
int i,j;
int tempmin,tempcode
Printf ("\ nInput number: \ n");
for(I = 0; I<8; i++)
scanf("%d ",p+I);
tempmin = * p;
for(I = 0; I<7; i++)
{
for(j = I; j & lt8; j++)
if(j = = I | | *(p+j)& lt; tempmin)
{ tempmin = *(p+j); //tempmin = *(p+I);
tempcode = j;
};
if (tempcode! =i)
{ *(p+tempcode)= *(p+I);
*(p+I)= tempmin; //*(p+j)= tempcode;
}
}
for(I = 0; I<8; i++)
printf("%d,",*(p+I)); // printf("%d ",,(p+I));
Returns (1);
}
Program fill in the blanks
Tk 10 1.c has an integer array a[]. By calling inv () subroutine, the storage locations of elements in a[] array are reversed. Please supplement the complete program in brackets [] and delete [] to run the test to meet the above requirements. You cannot add or delete rows or change the program structure.
void inv(int x[],int n)
{
int temp,I,j,m =[];
for(I = 0; I<= m;; i++)
{ j = n-I- 1;
temp = x[I];
[ ];
x[j]=[];
}
Return;
}
Master ()
{
int a[ 10]={4,5,6,7,8,9, 10, 1 1, 12,88 };
int I;
Printf ("original array: \ n");
for(I = 0; I< 10; i++)
printf("%3d ",a[I]);
printf(" \ n ");
inv(a, 10);
Printf ("inverse array: \ n");
for(I = 0; I< 10; i++)
printf("%3d ",a[I]);
printf(" \ n ");
}
Test 1. Program revision:
The gc56.c program is used to convert lowercase letters in a string into uppercase letters. There are two errors in the program. Please debug and correct them.
Yes, but you can't add or delete any statements. (20 points)
# include & ltstdio.h & gt
Invalid master (invalid)
{
char s[255];
int I;
scanf("%s ",s);
for(I = 0; s[I]; i++)
if(s[I]& gt; = ' a ' & amp& amps[I]& lt; = ' z ')//if(s[I]& gt; = ' b ' & amp& amps[I]& lt; ='z ')
s[I]= s[I]-' A '+' A '; //s[I]= s[I]+' A '+' A ';
printf("%s ",s);
}
Question 2: Fill in the blanks according to the procedure.
Tk56.c program is used to calculate the position of the row and column of the largest element in a 4×5 integer array. The following procedures are incomplete,
Please complete it in order to get the correct answer. (20 points)
# include & ltstdio.h & gt
Invalid master (invalid)
{
int a[4][5]={{4,8,9, 10, 12},
{2,5, 13, 17, 1 1},
{8 1,76,34,57,33},
{ 1,90,3,78,55}};
int max,max_row,max _ col
int i,j;
max = a[0][0]; //
max _ row = 0;
max _ col = 0;
for(I = 0; I<4; i++)
for(j = 0; j & lt5; j++)
if(max & lt; a[I][j]//
{
max = a[I][j];
max _ row = I;
max _ col = j;
}
printf("%d %d ",max_row,max _ col);
}
1. Fill in the blanks according to the procedure.
Tk57.c is used to output all prime numbers (prime numbers) between two integers m and n. An integer n is a prime number, which means that n can be divisible by 1 and its own n.
, not divisible by any integer between 2 and n- 1. For example, 7 is a prime number and 9 is not.
In the program, the outer loop variable I is used to control the range of integer selection, and the inner loop variable J is used to judge whether an integer I is a prime number. If so,
Output prime numbers, and the output of 5 prime numbers per line is controlled by variable S. ..
# Define M 4
# Define N 30
Master ()
{
int i,j,k,s = 0;
for(I = M; I < = n; i++)//
{ for(j = 2; J< me; j++)//
If(i%j== 0) interrupt;
if(j & gt; =i)
{ printf("%5d ",I);
s = s+ 1;
if(s % 5)printf(" \ n ");
}
}
printf(" \ n ");
}
2. Program error correction
The function of gc57.c is to exchange the maximum and minimum numbers in a given array. For example, the following eight numbers:
5,3, 1,4,2,8,9,6
Become:
5,3,9,4,2,8, 1,6
In the program, the exchange operation between the maximum number and the minimum number is realized by function call, so that the pointers max and min point to the maximum number and the minimum number respectively.
There are two mistakes between * * * * * * *, please correct them. Note: You cannot add or delete rows or modify the structure of the program.
Master ()
{
int I;
static int a[8]={5,3, 1,4,2,8,9,6 };
void jhmaxmin();
Printf ("original array: \ n");
for(I = 0; I<8; i++)
printf("%5d ",a[I]);
printf(" \ n ");
jhmaxmin(a,8);
Printf ("array after exchanging max and min: \ n");
for(I = 0; I<8; i++)
printf("%5d ",a[I]);
printf(" \ n ");
}
void jhmaxmin(p,n)
int *p,n; //int p,n;
{
int t、*max、*min、*end、* q;
end = p+n;
max = min = p;
for(q = p+ 1; Q< is over; q++)
{ if(* q & gt; * max)max = q;
if(* q & lt; * min)min = q; //if(* q & lt; max)min = q;
}
t = * max* max = * min* min = t;
}