I l @ ve RuBoard |
2, 7, 70, 64, 8, 2
It would produce the following output:
36 18 9 4 2 1
x > 5
scanf("%lf",&x) != 1
x == 5
scanf("%d", &x) == 1
x != 5
x >= 20
Line 4:
Should be list[10] .
Line 6:
Commas should be semicolons.
Line 6:
Range for i should be from 0 to 9, not 1 to 10.
Line 9:
Commas should be semicolons.
Line 9:
>= should be <= . Otherwise, when i is 1 , the loop never ends.
Line 10:
There should be another closing brace between lines 9 and 10. One brace closes the compound statement, and one closes the program. In between should be a return 0; line.
Here's a corrected version:
#include <stdio.h> int main(void) { /* line 3 */ int i, j, list[10]; /* line 4 */ for (i = 0; i < 10; i++) /* line 6 */ { /* line 7 */ list[i] = 2*i + 3; /* line 8 */ for (j = 1; j <= i; j++) /* line 9 */ printf(" %d", list[j]); /* line 10 */ printf("\n"); /* line 11 */ } return 0; }
Here's one way:
#include <stdio.h> int main(void) { int col, row; for (row = 1; row <= 4; row++) { for (col = 1; col <= 8; col++) printf("$"); printf("\n"); } return 0; }
It would produce the following output:
Hi! Hi! Hi! Bye! Bye! Bye! Bye! Bye!
It would produce the following output:
ACGM
It would produce the following output:
Saddle up my char
It would produce the following output:
Tbeemf!vq!nz!dibs
It would produce the following output:
Saddle up my charg
It would produce the following output:
$addle up my char
Here is the output we get:
11121314 *** 1 4 7 *** 1 5 2 7 4 9 8 11 *** +++++ ++++ +++ ++
mint
10 elements
type double values
Both i. and iii. are correct. In i., mint is the same as &mint[0] .
Because the first element has index , the loop range should be 1 to SIZE - 1 , not 1 to SIZE . Making that change, however, causes the first element to be assigned the value instead of 2 . So rewrite the loop this way:
for (index = 0; index < SIZE; index++) by_twos[index] = 2 * (index + 1);
Similarly, the limits for the second loop should be changed. Also, an array index should be used with the array name :
for (index = 0; index < SIZE; index++) printf("%d ", by_twos[index]);
One dangerous aspect of bad loop limits is that the program may work; however, because it is placing data where it shouldn't, it might not work at some time in the future, forming sort of a programming time bomb.
It should declare the return type as long , and it should have a return statement that returns a long value.
Typecasting num to long makes sure the calculation is done as a long calculation, not an int calculation. On a system with a 16-bit int , multiplying two int s produces a result that is truncated to an int before the value is returned, possibly losing data.
long square(int num) { return ((long) num) * num; }
Here is the output:
1: Hi! k = 1 k is 1 in the loop Now k is 3 k = 3 k is 3 in the loop Now k is 5 k = 5 k is 5 in the loop Now k is 7 k = 7
I l @ ve RuBoard |