Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Showing posts with label power function. Show all posts
Showing posts with label power function. Show all posts

Thursday, December 18, 2014

Program to find place value of all digits of any number given by user using for loop in C.


Place value of number using for loop


Code Box
----------------------------------------------

/*Program to find place value of all digits of any number given by user using for loop in C */

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int num,num1,rem,pval,rev,len,l;
clrscr();

rev=0;
printf("\n\tSum of Digits Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num; //to save actual number

/*Finding the length of number & reverse */ 
for(len=0;num1>=1;len++)
{
rem=num1%10;
num1=num1/10;
rev=rev*10+rem;
}


/*Calculation the place value */
for(l=len-1;rev>=1;l--)
{
rem=rev%10;
rev=rev/10;
pval=rem*pow(10,l);
printf("\nPlace value of %d is = %d",rem,pval);
}
getch();

}

Program to find place value of all digits of any number given by user using while loop in C.


Place value of number by while loop



Code Box
-----------------------------------------------------

/*Program to find place value of all digits of any number given by user using while loop in C */

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int num,num1,rem,pval,rev,len;
clrscr();
len=0;
rev=0;
printf("\n\tSum of Digits Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num; //to save actual number

/*Finding the length of number & reverse */ 
while(num1>=1)
{
rem=num1%10;
num1=num1/10;
rev=rev*10+rem;
len++;
}


/*Calculation the place value */
len=len-1;
while(rev>=1)
{
rem=rev%10;
rev=rev/10;
pval=rem*pow(10,len);
printf("\nPlace value of %d is = %d",rem,pval);
len--;
}
getch();

}

Program to find place value of all digits of any number given by user using do while loop in C.


Place value of number


Code Box
-------------------------------------------------

/*Program to find place value of all digits of any number given by user using do while loop in C. */

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int num,num1,rem,pval,rev,len;
clrscr();
len=0;
rev=0;
printf("\n\tSum of Digits Finder");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num; //to save actual number

/*Finding the length of number & Number reverse */ 
do
{
rem=num1%10;
num1=num1/10;
rev=rev*10+rem;
len++;
}while(num1>=1);



/*Calculation the place value */
len=len-1;
do
{
rem=rev%10;
rev=rev/10;
pval=rem*pow(10,len);
printf("\nPlace value of %d is = %d",rem,pval);
len--;
}while(rev>=1);

getch();

}

Wednesday, December 10, 2014

Program to find Armstrong number with power function in C.


Armstrong number in C.


Code Box
---------------------------------------------

/*Program to find Armstrong number with power function*/

/*Armstrong number means sum of nth power of each digits of a given number.
Example: 123 is a given number than 
Total number of digits= 3
so for checking 123 is Armstrong or not we need to do
sum=Cube(1)+Cube(2)+Cube(3)
and if sum==123 than it is an Armstrong number.

*/

/*We need to find:
Step1:Finding Length of number
Step2:Each digits 
Step3:power digits with length
Step4:calculate sum
Step5:Checking sum==number.

*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int p,num,num1,len,i,sum;
clrscr();

len=0;
sum=0;

printf("\n\tArmstrong Number Checker");
printf("\n-------------------------");
printf("\nEnter a number:");
scanf("%d",&num);

num1=num;

/*Step1:Finding length of number*/


while(num1>=1)
{
i=num1%10;  //Extraction of digits
num1=num1/10; //Reduction of number
len++;
}

printf("\nNumber of digits in number : %d",len);

/*Calculation of Armstrong number */

num1=num;

printf("\nAt Initial sum=%d",sum);
printf("\n------------------------");
while(num1>=1)
{
i=num1%10; //Step2
printf("\nFor digit=%d",i);
num1=num1/10;
printf("\nNumber =%d",num1);
p=pow(i,len); //Step3
sum=sum+p;  //Step4
printf("\nSum=%d",sum);

printf("\n----------------------\n");
}


printf("\nTotal sum: %d",sum);
/*Step 5 */
if(sum==num)
{
printf("\nNumber %d is an Armstrong number ",num);
}
else
{
printf("\nNumber %d is not an Armstrong number ",num);
}
getch();
}




Sunday, December 7, 2014

Program to calculate sum of square series using power function and while loop in C.


sum of square series using power function and while loop


Code Box
------------------------------------------------

/*program to calculate sum of the series 
(1*1)+(2*2)+(3*3)+(4*4)+.......+(n*n).
Square number series. 
by using power function.
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>   //for power function
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nSquare Number Series ");

printf("\nSeries= ");

i=1;              //initialization

while(i<=num)
{

sum=sum+pow(i,2);  //power function

printf("+ (%d*%d)",i,i);

i++;            //increment post fix operator 

}

printf("\n\nSum of series= %d",sum);

getch();
}



Program to calculate sum of the square series using power function and for loop in C.


square sum using power function


Code Box
-------------------------------------------------

/*program to calculate sum of the series 
(1*1)+(2*2)+(3*3)+(4*4)+.......+(n*n).
Square number series. 
by using power function.
where n is the limit entered by user.
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,sum,num;

clrscr();

sum=0;

printf("\nEnter limit : ");
scanf("%d",&num);

printf("\nSquare Number Series ");

printf("\nSeries= ");
for(i=1;i<=num;i++)
{
sum=sum+pow(i,2);
printf("+ (%d*%d)",i,i);
}

printf("\n\nSum of series= %d",sum);

getch();
}



Saturday, December 6, 2014

Program to calculate sum of factorial series using for loop and power function in C.






Code Box
-------------------------------------------

/*Program to calculate sum of series

 1/1!+1/2!+1/3!+.......+1/n!.
 by power function.

 where n is the value entered by user
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n,j,mul;
float sum;
clrscr();
sum=0;

printf("\nEnter limit number : ");
scanf("%d",&n);


printf("\nSeries=");

printf("\n---------------------\n");

for(i=1;i<=n;i++)
{
mul=1;
printf(" +1/%d! ",i);

for(j=1;j<=i;j++)
{
mul=mul*j;
}

sum=sum+pow(mul,-1); //power function

}

printf("\n---------------------\n");

printf("\nSum of series= %.3f",sum);

getch();
}

Program to calculate sum of series using for loop and power function in C,


sum of series



Code Box
------------------------------------

/*Program to calculate sum of series

 1/(1square)+1/(2 square)+1/(3 square)+.......+1/(n square).
 by power function.

 where n is the value entered by user
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum;
clrscr();
sum=0;

printf("\nEnter limit number : ");
scanf("%d",&n);


printf("\nSeries=");

printf("\n---------------------\n");

for(i=1;i<=n;i++)
{

printf(" +1/(%d*%d) ",i,i);
sum=sum+pow(i,-2); //power function

}

printf("\n---------------------\n");

printf("\nSum of series= %.3f",sum);

getch();
}


Program to calculate sum of series using for loop in C.


Sum of series

Sum of series


Code Box
-----------------------------------------------

/*Program to calculate sum of series

 1/(1square)+1/(2 square)+1/(3 square)+.......+1/(n square).
 by power function.

 where n is the value entered by user
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum;
clrscr();
sum=0;

printf("\nEnter limit number : ");
scanf("%d",&n);


printf("\nSeries=");

printf("\n---------------------\n");

for(i=1;i<=n;i++)
{

printf(" +1/(%d*%d) ",i,i);
sum=sum+pow(i,-2); //power function

}

printf("\n---------------------\n");

printf("\nSum of series= %.3f",sum);

getch();
}



Program to calculate sum of series using for loop in C.





Code Box
-----------------------------------------------

/*Program to calculate sum of series

 1/1+1/2+1/3+.......+1/n.
 by power function.

 where n is the value entered by user
*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float sum;
clrscr();
sum=0;

printf("\nEnter limit number : ");
scanf("%d",&n);


printf("\nSeries=");

printf("\n---------------------\n");

for(i=1;i<=n;i++)
{

printf(" +1/%d ",i);
sum=sum+pow(i,-1); //power function

}

printf("\n---------------------\n");

printf("\nSum of series= %.3f",sum);

getch();
}