Hey guys,

I'm a newbie in C and I've got to make an app:

Users enter 10 numbers;
I've got to compare them;
At the end tell the user if
a) Number are decreasing (ex: 10 9 8 7 6 5 4 3 2 1 0)
b) Number are creasing (ex: 1 2 3 4 5 6 7 8 9 10)
c) Number are equals (ex: 4 4 4 4 4 4 4 4 4 4)
d) Number are disorderly (ex: 9 8 2 7 4 9 2 3 0)

#include <stdlib.h>
#include <stdio.h>

int main ()

{

int Vecteur[10] = {0}, i, CompteurA = 0, CompteurB = 0;

printf("Entrez vos dix nombres: \n");
for(i = 0; i < 9; i++)
{
scanf("%d ", &Vecteur[i]);
}
for(i = 0; i < 9; i++)
{
if(Vecteur[i] > Vecteur[i+1])
{
CompteurA++;
}
if(Vecteur[i] < Vecteur[i+1])
{
CompteurB++;
}
}

printf("%d\n", CompteurA);
printf("%d", CompteurB);
if(CompteurA == 9)
{
printf("Decroissant");
}
else
{
if(CompteurB == 8)
{
printf("Croissant");
}
}
}

I haven't done yet the rest but I was wondering if we were oblige to use all these "if"...

Is there an other way but a newbies way?

Thanks.

4
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by Snehamathur

What exactly do you mean but a newbies way? Are you looking for an easier method?

Yeah that's it

Its easier to make such program using If-else, the logic could be quite simple.. think a bit...

Try this program:

# include <stdio.h>

int main()
{
int i,flag=0;
int num[10];
printf("\n\n\t\t Enter 10 values:");
for(i=0;i<10;i++)
scanf("%d",&num[i]);

for(i=0;i<9;i++)
{
if(num[i]<num[i+1])
flag++;
else if(num[i]>num[i+1])
flag--;
}

if(flag == -9)
printf("\n\n  decreasing..");
else if(flag == 9)
printf("\n\n  increasing..");
else if(flag == 0)
printf("\n\n  equals");
else
printf("\n\n Disorderly");

return 0;
}

Thanks vinit.
So it's the best way if-else... Thanks

there could be another ways to solve this but i have doubt about simplicity. It's already explained in a simple way.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.