程序在运行时不会显示任何内容,仅显示“ 0”值

时间:2019-03-30 18:30:51

标签: c++ codeblocks

它应该按以下顺序显示在屏幕上:

  • 偶数个数字;
  • 第一个数字与最后一个数字相等的数字(为此我做了“ bool cifre(int x)”);
  • 在“ g”文件中,它应该显示我在向量的最大值和最小值之间进行的最后一次操作。

我运行它并且只在屏幕上显示“ 0”,并且没有更多。请帮忙!

 #include <iostream>
 #include <fstream>
 #include <math.h>

 using namespace std;
 int n , v[101] , i , a , u , p , gasit=0 ;

 bool cifre( int x )
 {
 a = x ;
 u = x%10 ;
 while ( x!=0 )
{ 
    p = x%10 ;
    x = x/10 ;
}
if( p == u )
    return true ;
}

int main()

{
 ifstream f ( "atestat.in" ) ;
 ofstream g ( "atestat.out" ) ;
 for( i=1 ; i<=n ; i++ )
    {
      f >> v[i] ;
      if( v[i]%2 == 0 && i%2 != 0 )
        cout << v[i] ;
    }
  int min=v[n] ;
  int max=v[1] ;
  for( i=1 ; i<=n ; i++ )
    if ( cifre( v[i] ) == true )
       {
          cout << v[i] << " " ;
          gasit++ ;
        }

  if ( gasit==0 )
    cout << "NU EXISTA" ;
  cout << endl ;
  for( i=1 ; i<=n ; i++ )
    {
      if ( v[i] > max )
        max = v[i] ;
      if ( v[i] < min )
        min = v[i] ;
    }
   cout << ( max + min ) /. 2 ;
   f.close() ;
   g.close() ;
   return 0 ;
 }

1 个答案:

答案 0 :(得分:1)

您启动了一个for循环,以'n'结尾,但尚未给它赋值。

n=3; // example
for( i=1 ; i<=n ; i++ )