C and C++ Programming Blog
RSS Feed

Quicksort in C Programming Language

Sunday, 16 March 2008 07:42
Quicksort is a well-known sorting algorithm developed by C.A.R. Hoare: Quicksort. Computer Journal, Vol. 5, 1, 10-15 (1962). Quicksort is said to be the fastest sorting algorithm in practice. On average it makes Θ(nlogn) (big O notation) comparisons to sort n items, but in the worst cases it isas slow as bubble sort. Visually you can see below that how quicksort works (divide and conquer strategy). More...

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Top Programming tips for C and C++ Programmers

Saturday, 15 March 2008 07:38

Today I will discuss top coding tips which can be applied to any particular programming language. Also the tips will help you to write self documented programs which are easy to maintain and understand by anyone. 

Design first then code

Days are gone when we use to take pen and paper and write the pseudo code first draw the flow diagrams of the program. And at the end write the code on computer. Days are changed but still we need to apply SDLC (Software Development Life Cycle) on every program we create. This makes the program bug/error free as well as maintenance easy. I suggest you read Martin Fowler's excellent article Is Design Dead? which explains it in more details. More...

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Programming Mouse in C and C++

Monday, 18 February 2008 07:28

I was quite busy for the past few days in preparing some reports for my university, but was feeling a bit free today. I was thinking about what to write today. Having browsing throught the forums and few webpages I thought of writing about mouse programming in C and C++. I have written many programs, about programming mouse in C, before and explained the theory as well.

So what's today? Today I will provide some links about mouse programming and little description about those tutorials.More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Learning Computer Programming - What would you know?

Thursday, 14 February 2008 07:25

While looking around the internet I come across a video tutorial titling "What every would be programmer should know before learning their first language" by Clive Scott. Basically this video is about the numbering system used in computers. But the author gives quite a good explanation of how the numbering system works and why binary number system is used in computers. Then the conversion of numbering system (binary to decimal and decimal to binary) also hex conversion is discussed.

The overall video is a perfect video for a new starter of programming. There is nothing specific to any programming language but it’s a general overview of computer programming and the background theory of what happens when a program is written and the compiled, linked and executed. Like the author says: More...

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Math.h library in C Programming

Saturday, 9 February 2008 07:21

Today I will try to explore math.h (library) header file provided to the programmers by turbo C++ compiler. Mostly people try to implement their own implementation of these functions; this is due to the lack of knowledge about Math library provided by turbo C++. So here we go.

Find the Square root of a number

Function: double sqrt(double); It calculates the positive square root of the input value which is given as double data type.

#include <math.h>
#include <stdio.h>
int main(void)
{
double dSqrtNumber = 36.0
double dSqrtResult;   
dSqrtResult = sqrt(dSqrtNumber);
printf("The square root of the number ");
printf("%lf is: %lf\n",  dSqrtNumber, dSqrtResult);
return 0;
} 

Find the Power of a number

Function: double pow(double x, double y) It calculates the value of xy . If both the values are 0 then the value returned by the function is 0. If the result is a more bigger number; which a variable of type double can not contain; then the function return an error (HUGE_VAL).

#include <math.h>
#include <stdio.h>
int main(void)
{
double dValuex = 5.0, dValuey = 5.0;
double dResult;
result = pow(dValuex, dValuey);
printf("%lf power %lf is: %lf\n", dValuex, dValuey, dResult);
return 0;
}

Find Ceil and Floor values

Functions: double ceil(double x); double florr(double x);

ceil() finds the smallest integer value of the value passed as the parameter, but the returned values is not greater than the values passed to the function. Where as floor() finds the largest integer value not bigger than the value passed as the parameter.

#include <math.h>
#include <stdio.h>
int main(void)
{
double dNumber = 50.54;
double dFloorValue, dCeilValue;
dFloorValue = floor(dNumber);
dCeilValue = ceil(dNumber);€
printf("Original number is:     %5.2lf\n", dNumber);
printf("Number rounded down %5.2lf\n", dFloorValue);
printf("Number rounded up   %5.2lf\n", dCeilValue);
return 0;
}

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Print pyramids and diamonds in C Language

Wednesday, 6 February 2008 07:17

I have been receiving lot of emails and requests through the forums and inline forums attached to the tutorials on my website C and C++ Programming Resources about how to print pyramids and diamonds in different formats. So I have written this article to demonstrate how you can print pyramids and diamonds using for loop and if condition. Building a pyramid in c programming is quite easy, but you must have the understanding of how for loop works.

Need the Source Code only - Click Here

Most people ask to print the diamond of the form below. but with slight modifications you can print any shapes you like and any thing you want. For example in the source I have commented few lines which print the numbers instead of the * to construct the diamons shape with numbers. Below is diamond which is actually constructed using two pyramids, one of them is upside down. Figure 2 explains it in more detail.More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 
Copyright © by MYCPLUS. All rights reserved. #