all the rest of the code works, but coming to the last point, that of the order of numbers, the code either tells me that it is in increasing form or it is neither. Could you help me understand why please?
#include <stdlib.h>
#include <stdio.h>
int main(){
int n;
int number;
int positive, negatives, null;
int even, odd;
int cont;
int rest;
int previous_number;
int increasing;
int decreasing;
increasing=1;
decreasing=1;
positive=0;
negative=0;
null=0;
even=0;
odd=0;
printf("insert a number\n");
scanf("%d",&n);
for(cont=1;cont<=n;cont++){
printf("insert a number\n");
scanf("%d",&number);
here the code works by checking if the number is positive, negative or null
if(number>0){
positive++;
}else if(number<0){
negatives++;
}else{
null++;
}
here also seeing if it is even or odd rest=number%2;
if(rest==0){
even=even+1;
}else{
odd=odd+1;
}
and here the code doesn't work
if(number>previous_number){
decreasing=0;
}else{
if(number<previous_number){
increasing=0;
}
else{
increasing=0;
decreasing=0;
}
previous_number=number;
}
printf("the positive numbers are: %d \n",positive);
printf("the negative numbers are: %d \n",negative);
printf("the null numbers are: %d \n",null);
printf("the even numbers are: %d \n",even);
printf("the odd numbers are: %d \n",odd);
if (increasing==1){
printf("the numbers are arranged in ascending order\n");
}else if(decrescente==1){
printf("the numbers are arranged in descending order\n");
}else{
printf("the numbers are arranged neither in increasing nor in decreasing order\n");
}
system("pause");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire