0
我知道這看起來很多,但它確實是不
它只是檢查是否從數組一個字符是一個元音,如果它在主/支持對角線它使櫃檯去+1。指針不計權[C]問題是輸出是主對角線= 31,支持對角線= 4。 我不知道問題出在哪裏,我現在一直在看這個問題。
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
void Dijagonala(char znakovi[5][5],int *glav,int *spor)
{
int i,j;
for(i=0;i<5;i++){
for(j=0;j<5;j++)
{
if (((znakovi[i][j] == 'a') || (znakovi[i][j] == 'e') || (znakovi[i][j] == 'i') || (znakovi[i][j] == 'o') || (znakovi[i][j] == 'u') ||
(znakovi[i][j] == 'A') || (znakovi[i][j] == 'E') || (znakovi[i][j] == 'I') || (znakovi[i][j] == 'O') || (znakovi[i][j] == 'U'))
&& (i==j))
*glav+=*glav+1;
else if (((znakovi[i][j] == 'a') || (znakovi[i][j] == 'e') || (znakovi[i][j] == 'i') || (znakovi[i][j] == 'o') || (znakovi[i][j] == 'u') ||
(znakovi[i][j] == 'A') || (znakovi[i][j] == 'E') || (znakovi[i][j] == 'I') || (znakovi[i][j] == 'O') || (znakovi[i][j] == 'U'))
&& (j+i == 4))
*spor=*spor+1;
}
}
}
int main()
{
char znakovi[5][5];
int gsam=0,ssam=0,i,j,test=5;
for(i=0;i<5;i++){
for(j=0;j<5;j++)
{scanf("%c",&znakovi[i][j]);
fflush(stdin);
}}
Dijagonala(znakovi,&gsam,&ssam);
printf("glavna %d \n Sporedna %d",gsam,ssam);
}
請解釋'* glav + = * glav + 1;'。它看起來像是想要成爲'(* glav)+ = 1;'。 – Yunnosch
'fflush(stdin);' - [不要那樣做](https://stackoverflow.com/questions/2979209/using-fflushstdin)。 – WhozCraig
@Yunnosch修好了!謝謝,我真的忽視了那個。 –