.exe has stopped working
This is my code but when i compile it on codeblocks it says .exe has stopped working after taking input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include<iostream>
using namespace std;
int digits(long int n[],int i)
{
int no=1,j=n[i];
while(j>1)
{
j=j/10;
no++;
}
return no;
}
int main()
{
int t,j=1,i=0,length;
long int n[1000];
cout<<"Enter number of test cases:";cin>>t;
cout<<endl;
while(i<t)
{
cin>>n[i];
cout<<endl;
i++;
}
i=0;
while(i<t)
{
length=digits(n,i);
int sum=0;
int div=10;
while(j<=length)
{
sum+=(n[i]%div);
div*=10;
}
cout<<sum<<endl;
}
}
|
Your second and third while loops will never end
why second loop? i put i++
These ones:
1 2 3 4 5 6 7 8 9 10 11 12
|
while(i<t)
{
length=digits(n,i);
int sum=0;
int div=10;
while(j<=length)
{
sum+=(n[i]%div);
div*=10;
}
cout<<sum<<endl;
}
|
They never end.
Topic archived. No new replies allowed.