C Program To Compute X ^ N

C program to compute the value of X ^ N, given X and N as inputs. Program accepts two integers x, n and computes the power of x to the n by using recursion function power().  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 <math.h>

void main()
{
long int x,n,xpown;
long int power(int x, int n);

printf("Enter the values of X and Nn");
scanf("%ld %ld",&x,&n);

xpown = power (x,n);

printf(" %d to the power %d = %ldn",x,n,xpown);
}

/*Recursive function to computer the X to power N*/

long int power(int x, int n)
{
if (n==1)
return(x);
else if ( n%2 == 0)
return (pow(power(x,n/2),2)); /*if n is even*/
else
return (x*power(x, n-1)); /* if n is odd*/
}
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 implement strlen function

Write a c program to find the length of a string without using the built-in function strlen(). Program will calculate the length of the string using for loop by going through each character of the string, till its end. 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()
{
char string[50];
int i, length = 0;

printf("Enter a stringn");
gets(string);

for (i=0; string[i] != ''; i++) /*keep going through each */
{ /*character of the string */
length++; /*till its end */
}
printf("The length of a string is the number of characters in itn");
printf("So, the length of %s =%dn", string, length);
}
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 convert days to years, weeks and days

Write a C Program to convert given number of days to a measure of time given in years, weeks and days. For example 375 days is equal to 1 year 1 week and 3 days (ignore leap year).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 DAYSINWEEK 7

void main()
{
int ndays, year, week, days;

printf("Enter the number of daysn");
scanf("%d",&ndays);

year = ndays/365;
week = (ndays % 365)/DAYSINWEEK;
days = (ndays%365) % DAYSINWEEK;

printf ("%d is equivalent to %d years, %d weeks and %d daysn",
ndays, year, week, days);
}
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 compute the surface area and volume of a cube

C Program to compute the surface area and volume of a cube. Program will accept the length of the sides and calculates surface area and volume of the cube. 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 <math.h>

void main()
{
float side, surfArea, volume;

printf("Enter the length of a siden");
scanf("%f", &side);

surfArea = 6.0 * side * side;

volume = pow (side, 3);

printf("Surface area = %6.2f and Volume = %6.2fn", surfArea, volume);
}
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 accept a string and a substring and check if the substring is present in the given string

C Strings:
Write a C program to accept a string and a substring and check if the substring is present in the given string. Program search’s given substring is in the string or not, and prints the appropriate message. 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 main()
{
char str[80],search[10];
int count1=0,count2=0,i,j,flag;


clrscr();

puts("Enter a string:");
gets(str);

puts("Enter search substring:");
gets(search);

while (str[count1]!='')
count1++;

while (search[count2]!='')
count2++;

for(i=0;i<=count1-count2;i++)
{
for(j=i;j<i+count2;j++)
{
flag=1;
if (str[j]!=search[j-i])
{
flag=0;
break;
}
}
if (flag==1)
break;
}
if (flag==1)
puts("SEARCH SUCCESSFUL!");
else
puts("SEARCH UNSUCCESSFUL!");
getch();
}
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