为什么在输入数字执行时程序出错,内存不能为written
//Ctest4_03.cpp:Definestheentrypointfortheconsoleapplication.//#include"stdafx.h"#inc...
// Ctest4_03.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int a[5];
for ( int i = 0; i<5; i++ )
{
a[i] = 0;
}
int x, count = 0;
cin>>x;
while (x)
{
a[i] = x%10;
x = x/10;
count++;
}
for ( i = 4; i>=0; i-- )
{
x += a[i] * pow(10, (4-i));
}
cout<<"这是一个"<<count<<"位数"<<endl;
for ( i = 0; i<5; i++ )
{
cout<<a[i]<<", ";
}
cout<<"\n逆序后结果为:"<<x<<endl;
return 0;
} 展开
//
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
int a[5];
for ( int i = 0; i<5; i++ )
{
a[i] = 0;
}
int x, count = 0;
cin>>x;
while (x)
{
a[i] = x%10;
x = x/10;
count++;
}
for ( i = 4; i>=0; i-- )
{
x += a[i] * pow(10, (4-i));
}
cout<<"这是一个"<<count<<"位数"<<endl;
for ( i = 0; i<5; i++ )
{
cout<<a[i]<<", ";
}
cout<<"\n逆序后结果为:"<<x<<endl;
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询