GUYS i want to make a program that used to enter 7-digit number and determine the largest , smallest and the median and average of the seven number


i want also to display the entered number its equivalent in binary, ocatal and hexadecimal value


the sample output must be like this:


enter 7 digits
1234567


largest 7
smallest 1
median 4
average 5.25

you entered binary octal hexadecimal
1 001 1 1

2 010 2 2


upto 7 111 7 7


MY PROBLEM IS
my if else statement doesnt work i tink there's a logical error to my program
help plss ty..

[ATTACH][ATTACH]16806
HERE THE CODE THAT I MADE

Attachments
#include<stdio.h>
#include<conio.h>

void main()
{
long int numbers;
int a,b,c,d,e,f,g;
clrscr();
printf("enter the 7 digits:\n");
scanf("%ld", &numbers);

a=numbers/1000000;
printf("the first  number is %d\n",a);
b=numbers%1000000/100000;
printf("the second number is %d\n",b);
c=numbers%100000/10000;
printf("the third  number is %d\n",c);
d=numbers%10000/1000;
printf("the fourth number is %d\n",d);
e=numbers%1000/100;
printf("the fifth  number is %d\n",e);
f=numbers%100/10;
printf("the sixth  number is %d\n",f);
g=numbers%10;
printf("the seven  number is %d",g);


  if(a==1|2|3|4|5|6|7|8|9|0<b&c&d&e&f&g)
  {
  printf("\nthe largest number is: %d",a);}

  else if(b==1|2|3|4|5|6|7|8|9|0<a&c&d&e&f&g)
  {
  printf("the largest number is: %d",b);}

  else if(c==1|2|3|4|5|6|7|8|9|0<a&b&d&e&f&g)
  {
  printf("the largest number is: %d",c);}

  else if(d==1|2|3|4|5|6|7|8|9|0<a&c&b&e&f&g)
  {
  printf("the largest number is: %d",d);}

  else if(e==1|2|3|4|5|6|7|8|9|0<a&c&d&b&f&g)
  {
  printf("the largest number is: %d",e);}

  else if(f==1|2|3|4|5|6|7|8|9|0<a&c&d&e&b&g)
  {
  printf("the largest number is: %d",f);}

  else if(g==1|2|3|4|5|6|7|8|9|0<a&b&c&d&e&f)
  {
  printf("the largest number is: %d",g);}




getch();
}

>>if(a==1|2|3|4|5|6|7|8|9|0<b&c&d&e&f&g)

comparisons don't work like that in C or C++ languages. First off, variable a is only one digit, so why are you bothering to check that it is a number between 0 and 9? There are no other possibilities.

Put all the numbers in an array so that they can be easily sorted from hightest to lowest. After that all you have to do is print the first and last numbers in the array.

If you have not learned arrays yet, then you will have to do something like this, which can be very very awkward, error prone, and wordy.

if( (a<b) && (a<c) && (a<d) && (a<e) && (a<f) && (a<g) )
{
    // blabla
}
else
if( (b<a) && (b<c) && (b<d) && (b<e) && (b<f) && (b<g) )
{
    // blabla
}
// etc etc for all possible compinations if the 7 digits

This is an exercise in chapter 4 of Stroustrup's book on programming in C++.

You enter the digits into an vector using the push_back operator.
Use the sort(vector.begin, vector.end) to rank the digits from lowest to highest.
vector[0] = lowest digit, vector[vector.size()-1] = highest digit, vector[(vector.size()-1)/2] = median digit assuming an odd number of digits, then sum the vector elements and divide by vector.size() to find the mean.

This article has been dead for over six months. Start a new discussion instead.