D
darklight
Q: write a program so that excepts six even numbers
or until the number 99 is entered.
I should of add display only the even numbers entered
sorry!!
the two programs that were wrote done this:
First posted on 21/12/03
one of the replys Wrote:
#include<stdio.h>
int main(void) {
int variable[6], ctr = 0, nbr=0;
printf("Enter 6 values no decimal point or 99 to Quit\n");
for(ctr=0;ctr<6;ctr++) {
scanf("%d",&nbr);
if(nbr % 2 == 0) {
variable[ctr] = nbr;
}
else if(nbr == 99) {
variable[ctr]=99;
puts("Exiting program");
break;
}
else {
puts("number not an even number try again");
}
}
puts("");
for(ctr = 0; ctr < 6 && variable[ctr] != 99; ctr++)
{
printf("%d value %d\n",ctr +1,variable[ctr]);
}
return 0;
}
_________________________________________________________________
When i run program i get
the output
input 43,24,46,78,99
out put
1 value 1073934432
2 value 24
3 value 48
4 value 78
____________________
input 24,43,46,78,99
output
1 value 24
2 value 0
3 value 46
4 value 78
____________________
input 24,46,43,78,99
output
1 value 2
2 value 46
3 value -1073744904
4 value 78
And when i enter four even numbers and two odd numbers it displays
the four even numbers and garbage for the two odd numbers.
What makes me laugh is i am sure when i ran it for the first time
it worked but now i get the output as above.
Could one tell me what is going on?
or until the number 99 is entered.
I should of add display only the even numbers entered
sorry!!
the two programs that were wrote done this:
First posted on 21/12/03
one of the replys Wrote:
#include<stdio.h>
int main(void) {
int variable[6], ctr = 0, nbr=0;
printf("Enter 6 values no decimal point or 99 to Quit\n");
for(ctr=0;ctr<6;ctr++) {
scanf("%d",&nbr);
if(nbr % 2 == 0) {
variable[ctr] = nbr;
}
else if(nbr == 99) {
variable[ctr]=99;
puts("Exiting program");
break;
}
else {
puts("number not an even number try again");
}
}
puts("");
for(ctr = 0; ctr < 6 && variable[ctr] != 99; ctr++)
{
printf("%d value %d\n",ctr +1,variable[ctr]);
}
return 0;
}
_________________________________________________________________
When i run program i get
the output
input 43,24,46,78,99
out put
1 value 1073934432
2 value 24
3 value 48
4 value 78
____________________
input 24,43,46,78,99
output
1 value 24
2 value 0
3 value 46
4 value 78
____________________
input 24,46,43,78,99
output
1 value 2
2 value 46
3 value -1073744904
4 value 78
And when i enter four even numbers and two odd numbers it displays
the four even numbers and garbage for the two odd numbers.
What makes me laugh is i am sure when i ran it for the first time
it worked but now i get the output as above.
Could one tell me what is going on?