C program to print all the possible permutations of given digits

Write a C program to print all the possible permutations of given digits.
Permutations means possible way of rearranging in the group or set in the particular order.
Example:
Input:1, 2, 3
Output:1 2 3, 1 3 2, 2 1 3, 3 1 2, 2 3 1, 3 2 1
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* 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>
#include<conio.h>
int lev=-1,n,val[50],a[50];
void main()
{
int i,j;
clrscr();
printf("Enter how many numbers?n");
scanf("%d",&n);
printf("nEnter %d numbers:nn",n);
for(i=0;i<n;i++)
{
val[i]=0;
j=i+1;
scanf("%dnn",&a[j]);
}
visit(0);
getch();
}
visit(int k)
{
int i;
val[k]=++lev;
if(lev==n)
{
for(i=0;i<n;i++)
printf("%2d",a[val[i]]);
printf(" ");
}
for(i=0;i<n;i++)
if(val[i]==0)
visit(i);
lev--;
val[k]=0;

}
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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to toss a coin using random function.

Write a c program to toss a coin using random function.
In this Program,We use the rand()%2 function that will compute random integers 0 or 1.
Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* 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 <time.h>
#include <stdlib.h>

int main(void) {
int toss = 0;
int call = 0;
srand(time(NULL));

toss = rand() % 2;

printf("Say head or tail! press 0 for head and 1 for tail:nn");
scanf("%d", &call);
if(call==0 || call==1)
{
if(toss == call)
{
if(toss==1)
printf("You called it correctly ... it is tailn");
else
printf("You called it correctly ... it is headn");
}
else
{
if(toss==1)
printf("No way ...it is head !n");
else
printf("No way ... it is tail!n");
}
}
else
printf("Invalid call!!!!!nn");
return 0;
}
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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to Encrypt and Decrypt a password

C Strings:
Write a C program to Encryption and Decryption of password.
In this program we encrypt the given string by subtracting the hex value from it. Password encryption is required for the security reason, You can use so many functions like hash or other keys to encrypt. Read more about C Programming Language . and read the C Programming Language (2nd Edition). by K and R.

/***********************************************************
* 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 <string.h>

void encrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] - key;
}
}

void decrypt(char password[],int key)
{
unsigned int i;
for(i=0;i<strlen(password);++i)
{
password[i] = password[i] + key;
}
}
int main()
{
char password[20] ;
printf("Enter the password: n ");
scanf("%s",password);
printf("Passwrod = %sn",password);
encrypt(password,0xFACA);
printf("Encrypted value = %sn",password);
decrypt(password,0xFACA);
printf("Decrypted value = %sn",password);
return 0;
}
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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to Demonstrate the Recursive function.

Write a C program to demonstrate the recursive function.
Recursion  is the programming technique that a process invoking itself again and again. In this program, We reverse the given number and checks it is a palindrome or not. 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>

int main(){
clrscr();
int num,num1,rev;
printf("nEnter a number :n");
scanf("%d",&num);
num1=num;
//call recursive function
rev=reverse(num);

printf("nAfter reverse the number is :n%d",rev);
if(num1==rev){
printf("nnNumber %d is Palindromen",num1);
}else
{
printf("nnNumber %d is NOT a Palindromen",num1);
}

return 0;
}
int sum=0,r;
reverse(int num){
if(num){
r=num%10;
sum=sum*10+r;
reverse(num/10);
}
else
return sum;
return sum;
}

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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to demonstrate dynamic memory allocation example.

Write a C Program to demonstrate dynamic memory allocation example.
Dynamic memory allocation means you can allocate or relocate (manipulate) the memory at the run time, using malloc, calloc, and realloc functions.
Using malloc, We can allocate block of memory for a variable
Using calloc function, We can allocate multiple blocks of memory for a variable.
We can alter, reassign the allocated memory using the realloc function.
We can releasing the allocated memory using the free function. 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>

int main() {
int* grades;
int sum = 0, i, numberOfStudents;
float average;


printf("Enter the number of students: ");
scanf("%d", &numberOfStudents);
getchar();

if((grades = (int*) malloc(numberOfStudents * sizeof(int))) == NULL) {
printf("nError: Not enough memory to allocate grades arrayn");
exit(1);
}

printf("nEnter the grades of %d students (in separate lines):n", numberOfStudents);

for(i = 0; i < numberOfStudents; i++) {
scanf("%d", &grades[i]);
getchar();
}

/* calculate sum */
for(i = 0; i < numberOfStudents; i++)
sum += grades[i];

/* calculate the average */
average = (float) sum / numberOfStudents;

printf("nThe average of the grades of all students is %.2f",
average);

getchar();
return(0);
}

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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program to generate and print prime numbers in a given range.

Write a C program to generate and print prime numbers in a given range. Also print the number of prime numbers.
Prime number is a whole number and greater than 1, which is divisible by one or itself.
Example: 2, 3, 5, 7, 11, 13………… 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 <stdlib.h>
#include <math.h>

void main()
{
int M, N, i, j, flag, temp, count = 0;

clrscr();

printf("Enter the value of M and Nn");
scanf("%d %d", &M,&N);

if(N < 2)
{
printf("There are no primes upto %dn", N);
exit(0);
}
printf("Prime numbers aren");
temp = M;

if ( M % 2 == 0)
{
M++;
}
for (i=M; i<=N; i=i+2)
{
flag = 0;

for (j=2; j<=i/2; j++)
{
if( (i%j) == 0)
{
flag = 1;
break;
}
}
if(flag == 0)
{
printf("%dn",i);
count++;
}
}
printf("Number of primes between %d and %d = %dn",temp,N,count);
}



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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to demonstrate isalpha, isdigit, is space.

C Program to demonstrate the following functions:isalpha, isdigit, isspace.The same principles apply to isalnum, iscntrl, isgraph,islower, isprint, ispunct, isupper, isxdigit.
In the standard library ctype.h all the above functions are declared.
All the subroutines mentioned here, returns non zero(true), If the checked argument is true for the respective subroutines. 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> /* printf */
#include <ctype.h> /* isalpha isdigit isspace etc */

#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 */


}

//char_type:decides 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 c programs 
C Basic
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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to find the even numbers square and sum from 1 to 10.

C Program to find the even numbers square and sum from 1 to 10.
Even number is an integer, which is the multiple of two. In this program we use the for loop to produce the even numbers. Try to change the for loop limits you can get the various range results. 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>
int main()
{
int i,j,sum = 0;
clrscr();
printf("nEven numbers and their squares from 1 to 10:n");
for(i =1; i <=10; i++)
{
if(i % 2 == 0)
{
j = i * i;
printf("%dtt%d",i,j);
printf("n");
sum = sum + j;
}
}
printf("nnSum of even numbers square from 1 to 10 is: %d",sum);
return 0;

}
Read more c programs
C Basic
Number system
K and R C Programs Exercise

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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C program To show examples of the strtol function.

C program To show examples of the strtol function.
strtol() function converts the string to the long integer, and strtol() can accept the number in various bases, and converts it into the decimal number or base. 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 <stdlib.h>

main()
{
char num[10];

/* Test a valid number */
strcpy(num,"13");

printf("%s(Oct) is %i(Dec)n", num, strtol(num, NULL, 8));
printf("%s(Dec) is %i(Dec)n", num, strtol(num, NULL, 10));
printf("%s(hex) is %i(Dec)n", num, strtol(num, NULL, 16));

puts("----------------------------------");

/* Test a slightly valid number
* Returns the same results as
* above. */
strcpy(num, "13hzcd");

printf("%s(Oct) is %i(Dec)n", num, strtol(num, NULL, 8));
printf("%s(Dec) is %i(Dec)n", num, strtol(num, NULL, 10));
printf("%s(hex) is %i(Dec)n", num, strtol(num, NULL, 16));

puts("----------------------------------");

/* Test an invalid number
* Returns ZERO */
strcpy(num, "hzcd");

printf("%s(Oct) is %i(Dec)n", num, strtol(num, NULL, 8));
printf("%s(Dec) is %i(Dec)n", num, strtol(num, NULL, 10));
printf("%s(hex) is %i(Dec)n", num, strtol(num, NULL, 16));


puts("----------------------------------");

/* Test 0 base.
* This will look at the number
* and decide the base for its self!
*/
strcpy(num, "13");
printf("%s is %i(Dec)n", num, strtol(num, NULL, 0));

strcpy(num, "013");
printf("%s is %i(Dec)n", num, strtol(num, NULL, 0));

strcpy(num, "0x13");
printf("%s is %i(Dec)n", num, strtol(num, NULL, 0));

}
Read more c programs
C Basic
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!

To browse more C Programs visit this link
(c) www.c-program-example.com

C Program to demonstrate the strtok function.

C Program to demonstrate the strtok function.
strtok function breaks pointed by the string1 into sequence of tokens, which are sequences of contiguous characters separated by any of the characters that are part of delimiters.
In this program we split the test_string, i,e “string to split up ” to
string
to
split
up
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 <string.h>

main()
{

char test_string[50]="string to split up";



char *sub_string;

/* Extract first string */
printf("%sn", strtok(test_string, " "));

/* Extract remaining
* strings */
while ( (sub_string=strtok(NULL, " ")) != NULL)
{
printf("%sn", sub_string);
}
}
Read more c programs 
C Basic
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!

To browse more C Programs visit this link
(c) www.c-program-example.com