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

  • gaurav.bhorkar
    gaurav.bhorkar
    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.
  • Manish Goyal
    Manish Goyal
    correct .let us wait for more answers ..by the way have you checked run time of this program?
  • gaurav.bhorkar
    gaurav.bhorkar
    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?
  • Manish Goyal
    Manish Goyal
    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-#
  • gaurav.bhorkar
    gaurav.bhorkar
    Well, I couldn't find that in VC++. Even googling didn't help much.
  • Manish Goyal
    Manish Goyal
    It's okk..good job 😀
  • thechamp
    thechamp
    #include
    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, index=i;
    cout< 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

You are reading an archived discussion.

Related Posts

Dream Spark Yatra: Chennai(Genuine Microsoft Software for free) Microsoft Dreamspark Yatra - Chennai 2010, is a premier technological event hosted by Microsoft Chennai .NET User Group (Student) and Microsoft Student...
Hi. I 'm a student for Computer Since.i wanted to do a mini project in mobille programming with vb.net. Please help me with any idea.
hi...i am confused now a days , because i want to buy a laptop.i am not decided that which one is the best. because i do'nt want to go the...
TwInbox File Size:- 936 KB If you are a Microsoft ® Outlook ® user, you probably have it open all the time. Now you can have a fully-featured, powerful Twitter...
Hi, I am ME in Software engineering with good CGPA and did some lectureship in india. Came in US on H4,changed to H1b,did few projects in java.But now because of...