Wednesday, 21 November 2012

c language

c programming examples
C programming examples :- These
programs illustrate various programming
elements, concepts such as using
operators, loops, functions, single and
double dimensional arrays, performing
operations on strings, files, pointers etc.
Browse the code from simple c program
to complicated ones you are looking for,
every one of them is provided with
output. C program download with
executable files, so that you save on your
computer and run programs without
compiling the source code. All programs
are made using c programming
language and Codeblocks, most of these
will work under Dev c++ compiler also.
Download software you need to develop
codes. The first program prints "Hello
World" on screen.
C programming codes
Hello world
Print Integer
Addition
Odd or Even
Add, subtract, multiply and divide
Check vowel
Leap year
Add digits
Factorial
HCF and LCM
Decimal to binary conversion
ncR and nPr
Add n numbers
Swapping
Reverse number
Palindrome number
Print Pattern
Diamond
Prime numbers
Find armstrong number
Generate armstrong number
Fibonacci series
Print floyd's triangle
Print pascal triangle
Addition using pointers
Maximum element in array
Minimum element in array
Linear search
Binary search
Reverse array
Insert element in array
Delete element from array
Merge arrays
Bubble sort
Insertion sort
Selection sort
Add matrices
Subtract matrices
Transpose matrix
Multiply two matrices
Print string
String length
Compare strings
Copy string
Concatenate strings
Reverse string
Find palindrome
Delete vowels
C substring
Sort a string
Remove spaces
Change case
Swap strings
Character's frequency
Anagrams
Read file
Copy files
Merge two files
List files in a directory
Delete file
Random numbers
Add complex numbers
Print date
Get IP address
Shutdown computer
c program examples
Example 1 - C hello world program
/* A very simple c program printing a
string on screen*/
#include
main()
{
printf("Hello World\n");
return 0;
}
Output of above program:
"Hello World"
Example 2 - c program to take input from
user using scanf
#include
main()
{
int number;
printf("Enter an integer\n");
scanf("%d",&number);
printf("Integer entered by you is %d
\n", number);
return 0;
}
Output:
Enter a number
5
Number entered by you is 5
Example 3 - using if else control
instructions
#include
main()
{
int x = 1;
if ( x == 1 )
printf("x is equal to one.\n");
else
printf("For comparison use == as = is
the assignment operator.\n");
return 0;
}
Output:
x is equal to one.
Example 4 - loop example
#include
main()
{
int value = 1;
while(value<=3) { printf("Value is %d\n", value); value++; } return 0; } Output: Value is 1 Value is 2 Value is 3 Example 5 - c program for prime number #include
main()
{
int n, c;
printf("Enter a number\n");
scanf("%d", &n);
if ( n == 2 )
printf("Prime number.\n");
else
{
for ( c = 2 ; c <= n - 1 ; c++ ) { if ( n % c == 0 ) break; } if ( c != n ) printf("Not prime.\n"); else printf("Prime number.\n"); } return 0; } Example 6 - command line arguments #include
main(int argc, char *argv[])
{
int c;
printf("Number of command line
arguments passed: %d\n", argc);
for ( c = 0 ; c < argc ; c++) printf("%d. Command line argument passed is %s\n", c+1, argv[c]); return 0; } Above c program prints the number and all arguments which are passed to it. Example 7 - Array program #include
main()
{
int array[100], n, c;
printf("Enter the number of elements
in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for ( c = 0 ; c < n ; c++ ) scanf("%d", &array[c]); printf("Array elements entered by you are:\n"); for ( c = 0 ; c < n ; c++ ) printf("array[%d] = %d\n", c, array[c] ); return 0; } Example 8 - function program #include
void my_function();
main()
{
printf("Main function.\n");
my_function();
printf("Back in function main.\n");
return 0;
}
void my_function()
{
printf("Welcome to my function. Feel at
home.\n");
}
Example 9 - Using comments in a program
#include
main()
{
// Single line comment in c source code
printf("Writing comments is very useful.
\n");
/*
* Multi line comment syntax
* Comments help us to understand
code later easily.
* Will you write comments while
developing programs ?
*/
printf("Good luck c programmer.\n");
return 0;
}
Example 10 - using structures in c
programming
#include
struct programming
{
float constant;
char *pointer;
};
main()
{
struct programming variable;
char string[] = "Programming in
Software Development.";
variable.constant = 1.23;
variable.pointer = string;
printf("%f\n", variable.constant);
printf("%s\n", variable.pointer);
return 0;
}

Friday, 9 November 2012

flow charts

Flowchart Examples

To efficiently create the flowchart, it is best to start work from the flowchart examples. Now we will present some flowchart examples on flowcharting for proper understanding of this technique.
Flow Chart Example 1
Draw a flowchart to find the sum of first 50 natural numbers.
Answer: The required flowchart is given in Fig. 1.
Sum of first 50 natural numbers
Fig. 1 Flowchart for sum of first 50 natural numbers
Flow Chart Example 2
Draw a flowchart to find the largest of three numbers A, B, and C.
Answer: The required flowchart is shown in Fig 2
Flowchart for finding out the largest of three number
Fig 2 Flowchart for finding out the largest of three number
Flowchart Example 3
Draw a flowchart for computing factorial N (N!)
Where N! = 1?2?3?....N .
The required flowchart has been shown in fig 3
Answer:
Flowchart for computing factorial N
Fig 3 Flowchart for computing factorial N
Flowchart Example 4
A product assembly team in a gaming machine manufacturer were looking for ways of building the product more efficiently. They broke down the assembly process into a set of Flowcharts, showing how sub-assemblies were made and then built into the final product. Analysis of the reel assembly process revealed two improvements:
  1. The kit of parts was already checked by the kit assembly line, who were sometimes careless, as they knew the kit would be rechecked. The assembly line process was improved so the check here could be removed. This saved over two minutes per reel in checking, and up to fifteen minutes when the kit was faulty.
  2. Fitting the reel band after the reel had been attached to the base was awkward. Fitting the band before the reel was attached to the base was more comfortable and saved about a minute per reel.
The process Flowcharts, before and after improvement, are shown in Fig. 4.
Flowchart for gaming machine manufacturer
Fig 4 Flowchart for gaming machine manufacturer
The following flowchart examples can be edited and modified with our flowchart software.
Free Download Flowchart Software and View All Examples

c language

SELECTION STATEMENT: if

Selection Statements

Selection statements change the flow of program execution by evaluating the result of an expression, referred to as a condition. The if and switch statements are selection statements.

if Statement

An if statement evaluates a condition and executes its associated statement if the condition is true. Otherwise it skips the statement and processing continues on to the next statement following the if.


Figure 6-1: if Statement Diagram
Figure 6-1 illustrates the if statement. The expression that formulates the condition must evaluate to either true or false. True is any non-zero integer value.

if-else Statement

The if-else statement works like the if statement with one major difference. If the condition evaluates to false the statement following the else keyword will execute. A diagram of the if-else statement is shown in Figure 6-2.


Figure 6-2: if-else Statement Diagram

Monday, 5 November 2012

DATA TYPES IN C


In the C programming language, data types refers to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.
The types in C can be classified as follows:
S.N.Types and Description
1Basic Types:
They are arithmetic types and consists of the two types: (a) integer types and (b) floating-point types.
2Enumerated types:
They are again arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program.
3The type void:
The type specifier void indicates that no value is available.
4Derived types:
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types.
The array types and structure types are referred to collectively as the aggregate types. The type of a function specifies the type of the function's return value. We will see basic types in the following section where as other types will be covered in the upcoming chapters.

Integer Types

Following table gives you detail about standard integer types with its storage sizes and value ranges:
TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int2 or 4 bytes-32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int2 or 4 bytes0 to 65,535 or 0 to 4,294,967,295
short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
long4 bytes-2,147,483,648 to 2,147,483,647
unsigned long4 bytes0 to 4,294,967,295
To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.

Floating-Point Types

Following table gives you detail about standard float-point types with storage sizes and value ranges and their precision:
TypeStorage sizeValue rangePrecision
float4 byte1.2E-38 to 3.4E+386 decimal places
double8 byte2.3E-308 to 1.7E+30815 decimal places
long double10 byte3.4E-4932 to 1.1E+493219 decimal places
The header file float.h defines macros that allow you to use these values and other details about the binary representation of real numbers in your programs.

The void Type

The void type specifies that no value is available. It is used in three kinds of situations:
S.N.Types and Description
1Function returns as void
There are various functions in C who do not return value or you can say they return void. A function with no return value has the return type as void. For example void exit (int status);
2Function arguments as void
There are various functions in C who do not accept any parameter. A function with no parameter can accept as a void. For example int rand(void);
3Pointers to void 
A pointer of type void * represents the address of an object, but not its type. For example a memory allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any data type.
The void type may not be understood to you at this point, so let us proceed and we will cover these concepts in upcoming chapters.