Question: HERE IS MY C CODE: #include #define EVEN 50 int main() { int ar[EVEN]; int i; int j =2; for(i=0; i <50; i++){ if(j =0;i--){
HERE IS MY C CODE:
#include
#define EVEN 50
int main() {
int ar[EVEN];
int i;
int j =2;
for(i=0; i<50; i++){
if(j<=100){
ar[i] = j;
j=j+2;
}
}
for(;i>=0;i--){
printf(" %d", ar[i]);
}
}
OUTPUT:
1720516640 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2
I wonder why there is a number before 100? If I change the for() loop into this:
for(i = sizeof(ar);i>=0;i--){
printf(" %d", ar[i]);
}
The output is horrible:
895774541 794915937 1147430262 1769104708 795173999 1666723698 1701867372 1702257988 796488289 1919052108 795176048 1885417331 1919251285 792545364 1095786315 1380931397 1296126534 1598311513 1147093840 1482645248 895774541 795309410 1698967411 1952675172 1869762607 1684826485 1110401642 2020240247 1752131691 1786143077 1936030305 1735685992 1869504888 1633824053 1685015855 1635017028 1684371049 1919239215 1701080931 1479504485 1886350437 1986348079 2037539186 1651067951 1701605488 1630499698 1702057263 0 895774541 795309410 1698967411 1952675172 1869762607 1684826485 1110401642 2020240247 1752131691 1786143077 1936030305 1735685992 1869504888 1633824053 1685015855 1635017028 1684371049 1919239215 1701080931 1479504485 1886350437 1986348079 2037539186 1651067951 1701605488 1630499698 1702057263 1030255713 1885300076 1650553973 1667594341 0 0 32767 1606418367 32767 1606418314 32767 1606418283 32767 1606418264 32767 1606416648 0 0 0 0 32767 1606418154 32767 1606418116 32767 1606418102 32767 1606418061 32767 1606418050 32767 1606417993 32767 1606417975 32767 1606417958 32767 1606417872 32767 1606417848 32767 1606417829 32767 1606417677 32767 1606417661 1 3145808 32767 1606417422 32767 1606417285 32767 1606417157 32767 1606417081 32767 1606417015 32767 1606416885 0 0 32767 1606416776 0 1 0 0 32767 -419286443 32767 -419286443 32767 1606416392 810991129 -1901199337 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2
What happened and why?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
