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

Sunday, December 7, 2014

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


sum of odd number series


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

/*program to calculate sum of the series 
1+3+5+7+9.......+n
odd number series
where n is the limit entered by user.
*/

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

clrscr();

sum=0;

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

printf("\nOdd Number Series ");

printf("\nSeries= ");
for(i=1;i<=num;i++)
{

if(i%2!=0)
{
printf(" + %d ",i);
sum=sum+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();
}



Friday, December 5, 2014

Program to print factorial of any input number with fact as integer using do while loop in C.



factorial with fact as int


Code Box

------------------------------------------------------------

/*Program to print factorial of any input number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int num,fact;
/* If we take fact as integer, it can not be able
to store factorial of value greater than 8 */
fact=1;
clrscr();

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\n(When Fact as integer)\n");
printf("\nFactorial of %d is:",num);
printf("\n-----------------------------\n");
do
{
if(num==0)
{
printf("\n1"); //factorial of 0 is 1
break;
}
fact=fact*num;
num--;
}while(num>=1);

printf("\n%d",fact);

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

getch();
}