56 Replies - 742 Views - Last Post: 16 January 2013 - 03:38 PM
#31
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:35 PM
#32
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:38 PM
A for loop is three parts:
1. the loop control variable..
2. Condition to keep looping.
3. the increment/decrement for the loop control variable.
36 for (i=0;i<5;j++)
Why is 'j' being incremented when the lcv is 'i'?
38 for(l=0; l=5; l++)
Why is your condition (to keep looping) 'l=5'? When this starts off the lcv ('l') is zero... when is zero ever equal to five?
#33
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:40 PM
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
int matrix[5] [5];
int first[5];
int i,j,l;
for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}
for (i=0; i<5; i++)
{
printf("%2d", first[i]);
}
printf("\n");
for (i=0;i<5;j++)
{
for(l=0; l=5; l++)
{
printf ("enter %d row and %d column ", i, l);
scanf ("%d", &matrix[j][l]);
}
}
for (i=0; i=5; i++)
{
for(l=0; l=5; l++);
{
printf ("%3d", matrix[j][l]);
}
}
printf("\n");
scanf ("%d");
return 0;
}
#34
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:44 PM
46 for (i=0; i=5; i++) ... 48 for(l=0; l=5; l++);
Your for loop never starts.. because you tell the loop control variables to start at zero.. then you check to see if they are 5.. which they are not.. because you told them to start at zero... so the loop never happens. That's why people tend to use greater than and less than signs (as needed).
#35
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:45 PM
"enter 0 row and 5 column" i can enter as many numbers as i want but it wont go forward form that endlessly gives that
#36
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:47 PM
#37
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:49 PM
for(l=0; l=5; l++);
i thought the 5 there means the end of it.... so when it reaches 5 it stops.... how did i get my first one working with that logic....
right now it looks like that
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
int matrix[5] [5];
int first[5];
int i,j,l;
for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}
for (i=0; i<5; i++)
{
printf("%2d", first[i]);
}
printf("\n");
printf("=========================================================\n");
for (j=0;j<5;j++)
{
for(l=0; l=5; l++)
{
printf ("enter %d row and %d column ", j, l);
scanf ("%d", &matrix[j][l]);
}
}
for (j=0; j=5; j++)
{
for(l=0; l=5; l++);
{
printf ("%3d", matrix[j][l]);
}
}
printf("\n");
scanf ("%d");
return 0;
}
#38
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:49 PM
Quote
Look at it.. That conditions say "continue doing the loop when l equals five". It does *NOT* say "continue doing the loop while l is less than five". Less than and equals are two largely different concepts when it comes to loops.
One means 'you *MUST BE* ' and the other is a ceiling/max value.
#39
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:52 PM
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
int matrix[5] [5];
int first[5];
int i,j,l;
for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}
for (i=0; i<5; i++)
{
printf("%2d", first[i]);
}
printf("\n");
printf("=========================================================\n");
for (j=0;j<5;j++)
{
for(l=0; l=5; l++)
{
printf ("enter %d row and %d column ", j, l);
scanf ("%d", &matrix[j][l]);
}
}
for (j=0; j=5; j++)
{
for(l=0; l=5; l++);
{
printf ("%3d", matrix[j][l]);
}
}
printf("\n");
scanf ("%d");
return 0;
}
k fixed that...
now how do i make it look like a matrix? with like proper columns.... mine looks like a .... streight line of numbers
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
int matrix[5] [5];
int first[5];
int i,j,l;
for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}
for (i=0; i<5; i++)
{
printf("%2d", first[i]);
}
printf("\n");
printf("=========================================================\n");
for (j=0;j<5;j++)
{
for(l=0; l<5; l++)
{
printf ("enter %d row and %d column ", j, l);
scanf ("%d", &matrix[j][l]);
}
}
for (j=0; j<5; j++)
{
for(l=0; l<5; l++);
{
printf ("%3d \n", matrix[j][l]);
}
}
printf("\n");
scanf ("%d");
return 0;
}
#40
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:55 PM
#41
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:56 PM
#42
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 02:57 PM
#43
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 03:02 PM
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main (void)
{
int matrix[4] [4];
int first[5];
int i,j,l;
for (i=0;i<5;i++)
{
printf ("enter %d number for the first massive ", i);
scanf ("%d", &first[i]);
}
for (i=0; i<5; i++)
{
printf("%3d ", first[i]);
}
printf("\n");
printf("=========================================================\n");
for (j=0;j<4;j++)
{
for(l=0; l<4; l++)
{
printf ("enter %d row and %d column", j, l);
scanf ("%d", &matrix[j][l]);
}
}
for (j=0; j<4; j++)
{
for(l=0; l<4; l++);
{
printf ("%3d\n", matrix[j][l]);
}
printf ("\n");
}
printf("\n");
scanf ("%d");
return 0;
}
like that? it sill looks wrong though...
#44
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 03:03 PM
Quote
Wrong *HOW*?!
Remember this whole pattern thing - you need to explain to us what is going on and that helps us to help you.
#45
Re: Hello, i need help finishing my code
Posted 16 January 2013 - 03:07 PM
i entered these numbers
21
3
21
33
22
11
12
31
32
3
21
12
3
21
21
21
and this came out
22
32
3
2686792
where i want it to look normal like
1 2 3 4
2 2 2 2
1 2 2 2
|
|

New Topic/Question
Reply




MultiQuote





|