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 demonstrate the ‘fgets’ function.

Program to demonstrate the ‘fgets’ function. The program will count the number of lines in a file. This is a function of the UNIX command ‘wc’. 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 LINE_LENGTH 80

main()
{
FILE* fp;
char line[LINE_LENGTH];
int count=0;

fp=fopen("/home/DOC/C/c.html","r");
/* Count up the lines here. */
while ( fgets(line, LINE_LENGTH, fp) != NULL) count++;

printf("File contains %d lines.n", count);

fclose(fp);
}
Read more Similar C Programs
C Strings

Simple C Programs

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 calculate the Combinations and Permutations.

C Program to calculate the Combination and Permutations. Combination means way of selecting a things or particular item from the group or sets. nCr=n!/r!(n-r)!. Permutations means possible way of rearranging in the group or set in the particular order. 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>
#include <conio.h>

main()
{
int n , r, ncr( int , int);
long npr( int , int);
long double fact( int);
printf(" Enter value of n & r n");
scanf("%d %d",&n , &r);
if( n>= r)
{
printf( " %dC%d is %dn", n,r,ncr( n , r));
printf(" %dP%d is %ld", n,r,npr( n, r));
}
else
{
printf("WRONG INPUT?? enter the correct input");
}
}
long double fact( int p)
{
long double facts = 1;
int i;
for( i = 1; i<= p; i++)
facts = facts * i;
return( facts);
}

int ncr ( int n, int r)
{
return( fact( n) / (fact( r) * fact(n- r) ) ) ;
}

long npr( int n , int r)
{
return( fact( n) / fact( n- r));
}
Read more Similar C Programs
Learn C Programming
Recursion
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 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 find the character type.

C Program to find the Character types. Here we used the isdidit(), isalpa(), and isspace() functions.isdigit() function returns true if argument is a decimal digit, otherwise false. isalpa() function returns true if argument is a defined set of characters in c, otherwise false. isspace() function returns true if argument is a white space character (one of ‘ ‘ ‘f’ ‘n’ ‘r’ ‘t’ ‘v’), otherwise false. 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>
#include <ctype.h>

#define FALSE 0
#define TRUE 1

/* function declarations */
int char_type(char);

main()
{
char ch;
/* get a character from the keyboard */
printf(" Please enter a charcater => ");
ch = getc(stdin);

char_type(ch); /* Figure out the character type */
}


int char_type(char ch)
{
/* returns non zero if A-Z or a-z */
if ( isalpha(ch) != FALSE)
printf("%c is an Alpha character.n",ch);

/* returns non zero if 0-9 */
if ( isdigit(ch) != FALSE)
printf("%c is a numeric character.n",ch);

/* returns non zero if a space, CR, Tab, NL FF */
if ( isspace(ch) != FALSE)
printf("%c is white spacen", ch);

}
Read more Similar C Programs
Searching in C

C Strings

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 the ‘atof’ and ‘gets’ functions.

C Program to demonstrate the ‘atof’ and ‘gets’ functions. atof function converts the intial nptr string to the double. atof means ASCII to float. gets function reads string from the input stream. puts function prints string to the output stream This program will multiply to floating point numbers. The program will accept invalid data, and give you crap results as a result. 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>
#include <stdlib.h>

main()
{
char str1[80], str2[80]; /* define a couple o' strings. */
double result; /* Result of multiplication. */

puts ("This program will multiply to floating point numbers.");
puts ("The program will accept invalid data, and give you");
puts ("crap results as a result.n");
puts ("Please enter the first number.");
gets(str1);

puts ("And the second.");
gets(str2);

result = atof(str1) * atof(str2);
printf("Answer is %8.2fn", result);
}


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 which copies one file contents to another file.

C Program which copies one file contents to another file. Here we read the one file and copies the characters to another file which are existed in the disc. Here we read the file names from the command line.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>
#include <conio.h>
#include <process.h>

void main(int argc, char *argv[])
{
FILE *fs,*ft;
char ch;
clrscr();
if(argc!=3)
{
puts("Invalid number of arguments.");
exit(0);
}
fs = fopen(argv[1],"r");
if(fs==NULL)
{
puts("Source file cannot be opened.");
exit(0);
}
ft = fopen(argv[2],"w");
if (ft==NULL)
{
puts("Target file cannot be opened.");
fclose(fs);
exit(0);
}
while(1)
{
ch=fgetc(fs);
if (ch==EOF)
break;
else
fputc(ch,ft);
}
fclose(fs);
fclose(ft);
getch();
}

Read more Similar C Programs
File operations

Learn C Programming

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 the 2’s complement of a binary number.

C Program to calculate the 2’s complement of a binary number. 2’s complement of a number is obtained by scanning it from right to left and complementing all the bits after the first appearance of a 1. Thus 2’s complement of 11100 is 00100. 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>
#include<conio.h>

void complement (char *a);
void main()
{
char a[16];
int i;
clrscr();
printf("Enter the binary number");
gets(a);
for(i=0;a[i]!=''; i++)
{
if (a[i]!='0' && a[i]!='1')
{
printf("The number entered is not a binary number. Enter the correct number");
exit(0);
}
}
complement(a);
getch();
}
void complement (char *a)
{
int l, i, c=0;
char b[16];
l=strlen(a);
for (i=l-1; i>=0; i--)
{
if (a[i]=='0')
b[i]='1';
else
b[i]='0';
}
for(i=l-1; i>=0; i--)
{
if(i==l-1)
{
if (b[i]=='0')
b[i]='1';
else
{
b[i]='0';
c=1;
}
}
else
{
if(c==1 && b[i]=='0')
{
b[i]='1';
c=0;
}
else if (c==1 && b[i]=='1')
{
b[i]='0';
c=1;
}
}
}
b[l]='';
printf("The 2's complement is %s", b);
}



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