Installing cygwin on Windows from local directory

I will show you how to install CYGWIN on Windows..

First of all what is CYGWIN??to quote from wikipedia

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment. Thus it is possible to launch Windows applications from the Cygwin environment, as well as to use Cygwin tools and applications within the Windows operating context.

Installing CYGWIN from internet takes lot of time around 10-12 hours (depending upon internet speed) and there is around 22-23 g.b. of file that is downloaded if you are using full installation.But I required to use only compiler of C++, Java, Python, and other programming language..In C++ I have to write codes for Graphics and Networking..I could have used LINUX but due to heating and brightness problem in my laptop, I had to quit but I love LINUX..So I searched for an option and I found CYGWIN..

Download the file …It is of around 970 M.B and contains all the important things to run a code and also run code for graphics and networking

and extract it using 7 zip or Win Rar or any other decompressing software..Save the uncompressed folder to suppose

E:\temp

Now open the temp folder an run the setup.exe file and click on next until you find this screen

img1

 

Select “Install from local directory option.Click on Next

img2

and select the destination folder where you want to install it..remember it will be important when you set the path in Environment Variable..I had set it to “C:\cygwin64..click on next

img3

enter here the path where you have the folder that you have downloaded..in my case it was “E:\temp

now go on clicking next-next (three or four times) and you will see there will be a window appearing where you will see what is installing..It can take around 15-20 minutes or more..so be patient..

after installation is complete there will be an icon of Cygwin64 Terminal that will be appearing on Desktop.double click on it and type “gcc“..It will give an error telling gcc command not found..now its time to set Environment Variable..Be very cautious while doing this otherwise this can cause many problems..

Open C drive there you will find cygwin64 folder..double click on that..there you will find bin folder..double click on that and click on top of window you will get the address..for me it is “C:\cygwin64\bin“..copy it..

Now click on windows button..from right side select Control Panel..In control panel select system..from left side click on Advanced System Settings..In its advanced tab you will see Environment Variable written..just click on that..A new window will appear..Under System Variables scroll down until you find Path written

img4

Double click on path..now move till you find the last semicolon(;) or end and paste the copied path here..be sure that there is a separation between the previous path and new path by semicolon(;)

You have now successfully added the path..close the cygwin terminal and open it again..now type gcc and this time it will give you fatal error..no file found(if everything works correctly)..Voila!!you can now run C/C++/Python/JAVA/Ruby/Prolog etc code just you do it in LINUX

Write a simple hello world code and save it in C/C++ on desktop..you can move to desktop fro terminal by

cd C:

cd Users/(your computer name)/Desktop

Note:-Remember LINUX is case sensitive so any error may lead to incorrect path

compile the code using

cc filename.c

for C or

g++ filename.cpp

for C++

and run the code using 

./a.exe

To run JAVA code download JRE from oracle and add its bin folder to environment variable just as procedure above and compile java code using

javac filename.java

and run it using

java filename

Now for computer graphics code first of all enter

startxwin

in cygwin terminal..if a new window appears then its ok otherwise you have to install XWin package from net..run the setup file again and click on next and this time chose “install from internet“..select a mirror and select XWin package (probably the last one) and install all by clicking on Default once..specify the path to where you have to install “C:\cygwin64“..and again use following

startxwin

and run graphics code using

g++ filename.cpp -lGL -lglut -lGLU

in the new window that appeared..

Do ask if there is any problem or you find anything incorrect!!

I will be happy to help

DOWNLOAD LINK

Counting frequency of numbers in an array

I recently came across many contests where we are required to count the frequency of particular number or characters in an array.So i decided to post an efficient solution.Remember to initialize the frequency array initially with zero.Here is the code in C++


#include <cstdio>

using namespace std;

long int arr[100005], freq[100005] = {0};

int main()
{
    int n, i;
    printf("enter the number of elements\n");
    scanf("%d", &n);

    printf("enter the elements\n");

    for (i = 0;i < n;i++) {
        scanf("%ld", &arr[i]);
        freq[arr[i]]++;
    }

    for (i = 0;i < 1000005;i++) {
        if (freq[i] > 0) {
           printf("frequency of %d is = %ld\n", i, freq[i]);
        }
    }

    return 0;
}

Time complexity – O(n)

Space complexity – O(n)

Limitation – We cannot count the frequency of numbers whose value is greater than 10^6 because we are using freq[arr[i]].So maximum index that array in C++ can support is 10^6, so arr[i] should not exceed 10^6 ,above which we will get segmentation fault.

Extension – We can extend this technique to count the frequency of characters for a character array.We have to just take the input as  char arr[20000] instead of int arr[1000005],and rest will be same.But there will be corresponding ASCII count of the characters.

Prime Number implementation using Sieve of Eratosthenes

I implemented Sieve of Eratosthenes code in C++. It is one of the fastest method to find Prime numbers. Here is its C++ implementation.


#include &lt;cstdio&gt;
#define limit 1e7 + 10

typedef long long int lli;

lli primes[10000007] = {0};

void sieve()
{
    lli i, j;
    primes[1] = 0;
    primes[2] = primes[3] = 1;

    for (i = 5;i &lt;= limit;i += 2) {
         if (i % 3 == 0) {
                continue;
         }
         primes[i] = 1;
    }

    for (i = 5; i &lt;= limit || (i % 3) != 0;i += 2) {
         if (primes[i]) {
                for (j = 2 * i;j &lt;= limit;j += i) {
                        primes[j] = 0;
                }
         }
    }
}

int main()
{
    lli i, n;
    sieve();

    scanf(&quot;%lld&quot;, &amp;n);
    for (i = 1;i &lt;= n;i++) {
        if (primes[i]) {
           printf(&quot;%lld\n&quot;, i);
        }
    }

    return 0;
}

please tell if u find some bug in the code or any other method to improve it.