Thread: if-else prob..very basic so sorry to trouble u guys

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    9

    if-else prob..very basic so sorry to trouble u guys

    hey, sorry to trouble u guys.
    ok, i've got a prob...the qn goes like this:
    the user is supposed to input 10 integers (can be positive or negative) and write a prog to select the 2 largest integers and print these 2 largest integers...

    ok, my prog goes like this but it does not work...WHY?i don't understand...oh and i'm using a standard ANSI compiler.

    #include <stdio.h>

    main ()
    {
    int num1, num2,.............num10;
    int ans1, ans2;

    printf ("10 intergers pls:");
    scanf ("%d%d%d%d%d%d%d%d%d%d", &num1, &num2,...&num10);

    if (num1 >num2){
    ans1 = num1;
    ans2 = num2;
    }

    if (num1 <= num2){
    ans2 = num1;
    ans1 = num2;
    }

    if (ans1 < num)
    ans1 = num3;

    if (ans2 < num3 && ans1 >= num3)
    ans2 = num3;
    .
    .
    .
    .
    .
    .
    /*same selection process for num4 to num10*/

    printf("the ans is %d and %d", ans1, ans2);

    return ;
    }

    is the selection process wrong?how shld it be corrected?

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    mhm, read all numbers in an array (using a loop)! Then you can easily sort the all numbers using qsort of stdlib.h!

    i don't think that so many variables are good...
    Hope you don't mind my bad english, I'm Austrian!

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    9
    yeah, thats a good idea thanks!!
    hmm, but if i wanna do it using if else cotrol structure then how should i write/edit this prog?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM
  2. Basic Window Creation, Dev C++ 4.9.9.0 Linking Error
    By Tronic in forum Windows Programming
    Replies: 2
    Last Post: 11-27-2004, 06:03 PM
  3. Basic Graphics programming in C, please help
    By AdRock in forum Game Programming
    Replies: 3
    Last Post: 03-24-2004, 11:38 PM
  4. Basic Calc
    By Universe in forum C++ Programming
    Replies: 12
    Last Post: 07-17-2002, 10:07 PM