English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

public int main
{

int j[50];
int i;
int k;
for (int i=0,i<50,i++)
{
j[i]=i+1;
}
for(k=0,k<50,k++)
{
while(j[i] {
int a;
a=k%j[i];
if(a!=0)
{
cout< }
else
{
return 1;
}
}
}
return 0;
}

2006-09-01 01:10:48 · 5 answers · asked by z~a~r~y~a~r A 1 in Computers & Internet Programming & Design

5 answers

It will be useful when u say what this program will do and it would be best when u had some comments in between..
But what i had understood in the above program is that you are trying to find the reminder of J[i] / K. and if that is not equal to 0 printing the value of K. The problem here in the program is with the while loop which is checking for the condition j[i] less than k. Since in the above loop the value of i = 50 the value of j[i] is always 51 and it can never be less than 0 (as k value starts from 0).
It would be better if your program looks like this
(i had not even changed any thing in the program, you can verify that..)

public int main
{

int j[50];
int i;
int k;
for (int i=0,i<50,i++)
{
j[i]=i+1;
} // the value of i is now 50.
for(k=0,k<50,k++)
{
while(j[i]
{
int a;
a=k%j[i];
if(a!=0)
{
cout< }
else
{
return 1;
}
}
}
return 0;
}

2006-09-01 01:45:27 · answer #1 · answered by Bhima M 2 · 0 0

Check the correct one
#include
#include
int main()
{

int j[50];
int k;
for (int i=0;i<50;i++)
{
j[i]=i+1;
}
for(k=0;k<50;k++)
{
while(j[i] {
int a;
a=k%j[i];
if(a!=0)
{
cout< }
else
{
return 1;
}
}
}
return 0;
}



U use , instead of ; in for loop.

2006-09-01 01:27:02 · answer #2 · answered by Elo 3 · 1 0

i have removed errors , run it now

int main()
{

int j[50];
int i;
int k;
for (i=0;i<50;i++)
{
j[i]=i+1;
}
for(k=0;k<50;k++)
{
while(j[i] {
int a;
a=k%j[i];
if(a!=0)
{
cout< }
else
{
return 1;
}
}
}
return 0;
}

2006-09-01 04:25:12 · answer #3 · answered by jassi 1 · 0 0

Hey u have made very silly mistake.. your whole program is correct but main should be function so it should be main() and NOT main

2006-09-01 02:09:22 · answer #4 · answered by Shamim P 1 · 0 0

you want nested for loops, so dont close the first for loop until the end . . .

2006-09-01 01:16:57 · answer #5 · answered by bow4bass 4 · 0 0

fedest.com, questions and answers