C Program to print the pyramid pattern.

C program to print the pyramid pattern. This program prints pyramid of 5 rows using a for loop. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
int main()
{
int r, c,t=5;

for ( r = 1 ; r <= 5 ; r++ )
{
for ( c = 1 ; c < t ; c++ )
printf(" ");

t--;

for ( c = 1 ; c <= 2*r - 1 ; c++ )
printf("*");

printf("n");
}


return 0;
}
Read more Similar C Programs
Learn C Programming

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate Ternary condition.

C Program to demonstrate the Ternary conditional operator(?). Ternary operator is a short hand combination of the if-else statement. You can use the ternary operator in initialize lists. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
int main()
{
int min,x,y;
printf("Enter two numbersn");
scanf("%d%d",&x,&y);
min=x <= y ? x : y;
/*
The ternary operator (?) can be rewritten using the if-else statement:
if(x<=y)
{
min=x;
}
else
{
min=y;
}*/
printf("n Small number is: %d",min);
return 0;
}
Read more Similar C Programs
Learn C Programming

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to Demonstrate the increment and decrement operators

C program which demonstrates the working of increment(++) and decrement(–) operators. Increment operator ++ adds 1 to its operand and Decrement operator — subtracts 1 from its operand.

These operators may be used either as a prefix operator or post-fix operator. Read more here: Increment and decrement operators

The Program

/* C Program to demonstrate increment and decrement operators */
main()
{
/*
* ++i -> i incremented before i is used.
* --i -> i decremented before i is used.
* j++ -> j is incremented AFTER j has been used.
* j-- -> j is decremented AFTER j has been used.
*/
int i=1,j=1;
puts("\tDemo 1");
printf("\t%d %d\n",++i, j++); /* O/P 2 1 */
printf("\t%d %d\n",i, j); /* O/P 2 2 */
i=1; j=1;
puts("\n\tDemo 2");
printf("\t%d \n", i=j++); /* O/P 1 */
printf("\t%d \n", i=++j); /* O/P 3 */
i = 0; j = 0;
puts("\n\tDemo 3");
if ( (i++ == 1) && (j++ == 1)) puts("Some text");
/* Will i and j get incremented? The answer is NO! Because
* the expression in the left of '&&' resolves to false the
* compiler does NOT execute the expression on the right and
* so 'j' does not get executed!!!!! */
printf("\t%d %d\n",i, j); /* O/P 1 0 */
}

Sample Output

Increment and decrement operators in c

Related programs

Airthmatic Operators
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page.

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate the ‘getchar’ function.

Program to demonstrate the getchar function. The program will read data entered via the keyboard. And returns the number of characters entered. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include <stdio.h>

#define RETURN 'n' /* n == return in UNIX
r == return in DOS */

main()
{
int count=0;
puts("Please enter some text.");
/* Count the letters in the 'stdin'
buffer. */
while ( getchar() != RETURN) count++;

printf("You entered %d charactersn", count);
}
Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to check the given number is Armstrong or not?

C Program to check the given number is Armstrong number or not?. Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits. Example: 153 = 1^3 + 5^3 + 3^3. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include<stdio.h>
void main()
{
int num,num1,arms=0,rem;

printf("Enter the number:n");
scanf("%d",&num);
num1=num;
while(num>0)
{
rem=num%10;
arms=arms+rem*rem*rem;
num=num/10;
}
if(num1==arms)
{
printf(" n%d is an Armstrong number",num1);
}
else
{
printf("n%d is NOT an Armstrong number",num1);
}

}
Read more Similar C Programs
Learn C Programming

Number System

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to Demonstrate #if, #else & #endif preprocessors.

C Program to demonstrate the Preprocessor directives like #if, #else, #define, #endif. C Preprocessors are not the program statements, they are executed before the actual compilation of the code. C Preprocessors substitute the code where they called, i.e they replace the code as they defined. #if, #else are the conditional directives. Here at the compile time #if value is false, so #else part is execute.
Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>

#define SWITCH 0

/* The #if can only perform
* INTEGER tests!!!!
*/
#if ( SWITCH == 1 )
#define TEXT "Example to #if"
#else
#define TEXT "Example to # else"
#endif

main ()
{
printf(TEXT);
}
Read more Similar C Programs
Learn C Programming

Number System

Preprocessor
You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate extern variable.

C Program to demonstrate extern variable. Extern variables are very useful in c,when the source code is in the two or more files, you can refer the variables from one file to another using extern variables. Extern variables are also global variable,but in explicit manner. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/

#include<stdio.h>
void write_extern(void);

extern int count;

void write_extern(void)
{
printf("count is %in", count);
}

int count = 5;

main()
{
write_extern();
}

Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to demonstrate functions.

C Program to demonstrate functions. C Functions are block of codes, performs the specific task. Default function in C is main(). Advantages of the functions are easy to understand, coding, well defined tasks, easy error handling. There are several ways to call the functions like, pass by value, pass by reference etc.. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/


#include<stdio.h>
int add( int, int); /* Function declaration */

main()
{
int i=1;
printf("i starts out life as %d.", i);

i = add(1, 1); /* Function call */

printf(" And becomes %d after function is executed.n", i);
}

/************************************************************************/

int add( int a, int b) /* Function definition */
{
int c;
c = a + b;
return c;
}
Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to Find out the size of the different data types

C Program to find the Size of Different data types. In This program we, find the size of the datatypes in c using sizeof() operator. sizeof() operator returns the its argument memory in bytes. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/





#include <stdio.h>
main()
{

printf(" short int is %2d bytes n", sizeof(short int));
printf(" int is %2d bytes n", sizeof(int));
printf(" int * is %2d bytes n", sizeof(int *));
printf(" long int is %2d bytes n", sizeof(long int));
printf(" long int * is %2d bytes n", sizeof(long int *));
printf(" signed int is %2d bytes n", sizeof(signed int));
printf(" unsigned int is %2d bytes n", sizeof(unsigned int));
printf("n");
printf(" float is %2d bytes n", sizeof(float));
printf(" float * is %2d bytes n", sizeof(float *));
printf(" double is %2d bytes n", sizeof(double));
printf(" double * is %2d bytes n", sizeof(double *));
printf(" long double is %2d bytes n", sizeof(long double));
printf("n");
printf(" signed char is %2d bytes n", sizeof(signed char));
printf(" char is %2d bytes n", sizeof(char));
printf(" char * is %2d bytes n", sizeof(char *));
printf("unsigned char is %2d bytes n", sizeof(unsigned char));
}
Read more  C Programs
Array In C

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com

C Program to Demonstrate getting the parameters from the command line.

C Program to getting the parameters from the command line. To pass the arguments from command line, in main function we have to declare two arguments . First one is number of arguments passed to the program and other one is pointer variable which gives the list of arguments passed. Read more about C Programming Language .

/***********************************************************
* You can use all the programs on www.c-program-example.com
* for personal and learning purposes. For permissions to use the
* programs for commercial purposes,
* contact [email protected]
* To find more C programs, do visit www.c-program-example.com
* and browse!
*
* Happy Coding
***********************************************************/



#include <stdio.h>

main(int argc, char *argv[]) {
int count;

/* Main takes two variables 'argc' is the number of parms on the
* command line and 'argv' is a pointer to each of the parameters.
*
* int argc -- integer number called 'argc'
* char *argv[] -- Character pointer array!
*/

printf("%i parameters entered on the command line.n", argc);

/*
* progname argc = 1
* progname parm1 parm2 argc = 3
*/

/*
* We take 1 from argc because
* the argv array starts at zero
* an ends at argc -1
*/

for (count = 0; count <= argc - 1; count++) {
/* printf expects a pointer
* to the text
*/

printf("parm %d is %sn", count, argv[count]);
}
}
Read more Similar C Programs
C Strings

Simple C Programs

You can easily select the code by double clicking on the code area above.

To get regular updates on new C programs, you can Follow @c_program

You can discuss these programs on our Facebook Page. Start a discussion right now,

our page!

Share this program with your Facebook friends now! by liking it

(you can send this program to your friend using this button)

Like to get updates right inside your feed reader? Grab our feed!

(c) www.c-program-example.com