35 Reusable Code Snippet Topics

Remove Filter
Member Avatar for
Member Avatar for ddanbe

Well, there was a thread about a frequency function and a bell curve in Excel. [url]http://www.daniweb.com/forums/thread295203.html[/url] So here it is how about to do the NORMDIST function in Excel in C#.

Member Avatar for dlhockey12
0
3K
Member Avatar for ddanbe

Wanted to let two forms work together. One form would be the input form and the main form would consume this data. I managed to succeed with the help of a few of my friends here at daniweb., who helped me setup a static form. Just posted a bit of …

Member Avatar for JamesCherrill
1
2K
Member Avatar for ddanbe

There are many pictures of hearts out there. I just wanted to draw a picture of a heart on my own from a math formula I found on the net. Seems there are many formulas to find. This is how it looks: ![Heart.PNG](/attachments/small/1/4c36fe9d031a39f8b3468f1c4f8a8f3d.PNG "align-left") Enjoy!

3
346
Member Avatar for xrjf

The present code snippet just does an especific task. This is, given an ordered sequence of natural numbers, starting at zero, generate all the different permutations there can be. When we talk about permutations, the order of the sequence does matter. So, the sequence 0, 1, 2 differs from 2, …

Member Avatar for xrjf
0
2K
Member Avatar for ddanbe

Short snippet in C# to do this classic trick, I could not find one on the web. Little, (even none!) error checking is done here.

Member Avatar for ddanbe
0
844
Member Avatar for ddanbe

One of the most, if not THE most, beautiful formulas in math, is from Euler: ![Euler_e_pi_i.png](/attachments/large/1/b32f45540a27b3efc328d14c60ee286c.png "align-center") It combines in it a relation between the number **e**, the number **Pi** and the complex number **i**, plus the basic math symbols 1, +, = and zero. Is that not amazing? More …

Member Avatar for JOSheaIV
1
608
Member Avatar for TrustyTony

Python helps in real life situation to automate things. This program helps you to prep up your kids ability to go over/under ten, which is essential not only by itself, but also when calculating with bigger numbers. Program is not any special, but shows how useful Python can be in …

Member Avatar for TrustyTony
0
266
Member Avatar for vckicks

The .Net Framework uses by default radians in its trigonometry calculations. Find out how to convert degrees to radians to use with C#

Member Avatar for ddanbe
1
703
Member Avatar for ddanbe

Don’t know if this is ever been done before, or even if it is a good way to do it. I’ll just await your comments if any. What I mostly found on the web is that if you want to define a polynomial you need to have an array containing …

0
441
Member Avatar for DavidB

Here is a small--complete--program that includes a sub-routine that inputs two matrices and then multiplies them. Notes: * 1) I happen to like taking input from a text file. It eliminates the need to type input from the console, especially when debugging, it prevents the possibility of making typos. * …

Member Avatar for Shellback3
3
2K
Member Avatar for xrjf

The days when the calculator had almost 3 thousand visits a day have gone. Since then, there have been several major versions and lots of minor versions. Somehow, I feel pleased in that the present core algorithm follows the rules of the first I read; of course, extending the simplicity …

0
398
Member Avatar for DavidB

Here is my first Code Snippet contribution: a C++ sub-routine that computes the roots of a quadratic equation. Notes: * This sub-routine checks if a = 0. * IF a = 0, then the equation is actually not a quadratic equation; it is a linear equation with one--if any--root. * …

Member Avatar for DavidB
1
711
Member Avatar for ddanbe

Complex numbers are seldom used in daily life, altough you could say that every real number is complex, but with the imaginary part equal to zero. And btw. "complex" is a bit of a misnomer, perhaps we should call them "easies", because often they make it easier to perform certain …

Member Avatar for ddanbe
0
1K
Member Avatar for vegaseat

This code example shows how to create a dictionary with row,column indexed (r,c) key tuples from a typical list of lists 2D matrix. Also an example is shown of the ease of processing the resulting dictionary.

Member Avatar for TrustyTony
5
6K
Member Avatar for ddanbe

While surfing the web I got to this site: [url]http://en.wikipedia.org/wiki/Fourier_series[/url] “Hey, I why not write something like this in C#!” The rather scary looking formulas did not withhold me to start coding (see below Fig. 1 and Fig. 2) The formula from Fig. 2 is hidden under one of the …

Member Avatar for skatamatic
0
3K
Member Avatar for ddanbe

When you want to draw something on a form you need a Graphics object. But a Graphics constructor isn’t public and if that is not enough the Graphics class is also sealed! This means you can’t create a Graphics object via the new keyword nor can you derive from the …

Member Avatar for skatamatic
0
4K
Member Avatar for TrustyTony

Here is class that can be fed directly from split stream like one number per line file (or [URL="http://www.daniweb.com/software-development/python/code/321725"]generator producing 'words'[/URL] from multiple numbers per line).

Member Avatar for Gribouillis
0
606
Member Avatar for ddanbe

What polar coordinates are is explained [url=http://en.wikipedia.org/wiki/Polar_coordinate_system]here[/url]. I wanted to draw some polar functions myself, so I changed my [url=http://www.daniweb.com/software-development/csharp/code/217204]plotting class [/url] a bit and added a polar struct to a new project.. Just posted code for the Plot class and the polar point structure here. You can find an …

2
998
Member Avatar for K0ns3rv

A little program I made to try and remeber C++, first program I've written in C++ in about a year. Tested and working under windows 7 64 bit, run via command line. If you have any improvements or ideas please leave a comment. Cheers K0ns3rv

Member Avatar for mrnutty
1
315
Member Avatar for ddanbe

I find C# very well suited for doing math and all sorts of calculations, so here is an example. Just start a Console application and fill in the code. Have fun! The code also shows a use of delegates and some Console functions. If you don't know what the Newton-Raphson …

0
3K
Member Avatar for TrustyTony

This I did also after 'spying' discussions in other forum. Of course you would use sieve prime generation for bigger numbers, but I proved other simple way for a change. Slightly more advanced primes list generator would use primes % 6 in (1,5) property: [CODE]def primes(n): """ primitive non-sieve prime …

Member Avatar for TrustyTony
0
654
Member Avatar for TrustyTony
Member Avatar for TrustyTony
Member Avatar for TrustyTony

With this code you can explore the functions of math module interactively seeing the docstrings automatically for each function. EDIT: The docstring was unfortunately from old code, this version copes with values like 'e' and multiple parameter functions.

Member Avatar for TrustyTony
0
216
Member Avatar for TrustyTony

Here another small snippet of mathematical nature returning all possible divisors of number. (set is, by the way, needed because of perfect squares Not possible to edit the snippet part but here the same with less stupid command line interface (not repeating the loop): [CODE]def divides(n): return sorted(set(sum( ([x,n/x] for …

Member Avatar for TrustyTony
1
808
Member Avatar for Gribouillis

This snippet defines a class LebsegueSet which instances represent sets of real numbers, namely finite unions of intervals. Set theoretical, topological and measure theoretical operations are implemented in pure python. Use freely and enjoy !

1
236
Member Avatar for fallopiano

Here I have a simple range function that can use floats as steps or increments. In a time test (using Psyco 1.6, python 2.5, and a basic PC), the normal frange function was able to go up to 1,000,000 from 0, by .3 , and finish that in about 0.5929 …

Member Avatar for Gribouillis
0
550
Member Avatar for ddanbe
Member Avatar for ddanbe
2
981
Member Avatar for naveenreddy61

the code takes each character and stores where and how many times a roman numeral appears and the assess the integer. this is my first code im posting. anything to make the code better is most welcome. roman numeral refers to M=1000 D=500 C=100 L=50 X=10 V=5 I=1 and uses …

Member Avatar for WaltP
0
889
Member Avatar for ddanbe

Whenever you hear the word recursion, factorials or Towers of Hanoi are never far away. Well here they get mentioned, because we are not going to talk about these guys at all! Iteration and recursion are in fact quite similar: they both loop until a certain condition is met. As …

2
3K

The End.