CrazyEngineers
  • Manish
    Manish

    MemberMar 6, 2010

    9 th c++ Problem

    Let us play with time:
    write a program to find index of smallest no in an array?

    The one whose program will take minimum execution time and with smallest exe file size will be appreciated
    😀
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • gaurav.bhorkar

    MemberMar 6, 2010

    Compiler used - Visual C++ Express 2008.

    Here is the code.
    #include "stdafx.h"
    
    int main ()
    {
        int arr[] = {5, 9, 2, 4, 5, 3, 9, 6, 7, 4};
        int smallest = arr[0];
        int index, i;
        for (i = 0; i < 10; i++)
        {
            if (arr[i] <= smallest)
            {
                smallest = arr[i];
                index = i;
            }
        }
        printf ("The smallest element in the array is %d and its index is %d\n", smallest, index);
        return 0;
    }
    I think size of executable may vary with the compiler used.
    Size of this exe when compiled using VC++ 2008 is 30 Kb.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 6, 2010

    correct .let us wait for more answers ..by the way have you checked run time of this program?
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberMar 6, 2010

    goyal420
    correct .let us wait for more answers ..by the way have you checked run time of this program?
    How to check the run time?
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 6, 2010

    I don't know about visual c++ but you can check it in turbo c++

    click on option 'compile' in menu bar...then click 'information'

    For more info have a look of this thread

    #-Link-Snipped-#
    Are you sure? This action cannot be undone.
    Cancel
  • gaurav.bhorkar

    MemberMar 6, 2010

    Well, I couldn't find that in VC++. Even googling didn't help much.
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberMar 6, 2010

    It's okk..good job 😀
    Are you sure? This action cannot be undone.
    Cancel
  • thechamp

    MemberMar 7, 2010

    #include<iostream>
    using namespace::std;
    int main()
    {
    int a[10]={5, 9, 2, 4, 5, 3, 9, 6, 7, 4},i,n,index;
    n=a[0],index=0;
    for(i=1;i<10;i++)
    if(a<n) n=a, index=i;
    cout<<index;
    return 0;
    }


    This code has executible file of size 464 kb in dev-cpp and 24 kb in turbo c, also the code has 0.1 millisecond execution time in Turbo, dont know how to find time in dev-cpp
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register