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

Sunday, December 7, 2014

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


sum of square series using while loop



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

/*program to calculate sum of the series 
(1*1)+(2*2)+(3*3)+(4*4)+.......+(n*n).
Square 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("\nSquare Number Series ");

printf("\nSeries= ");

i=1;                   //initialization 

while(i<=num)
{
sum=sum+(i*i);
printf("+ (%d*%d)",i,i);

i++;       // increment post fix operator 

}

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

getch();
}


Saturday, December 6, 2014

Program to calculate sum of series using for loop without 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).

 where n is the value entered by user.

 =>Explicit type conversion

*/

#include<stdio.h>
#include<conio.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+(float)1/(i*i); //Explicit type conversion

}

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

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

getch();
}


Sunday, November 30, 2014

Program to Solve Quadratic Equation in C.





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


/* Program to Solve Quadratic Equation */

/* In quadratic equation we need values of a,b,c
and D=(b square -4.a.c)
and every thing depends on the value of D
*If D grater than 0 multiple and real root
*If D==0 only single root
*If D is less than 0 than imaginary roots

from codeboxc.blogspot.com

*/

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,D;

float x1,x2,D1;

clrscr();

printf("\nEnter Values");
printf("\n a = ");
scanf("%d",&a);

printf("\n b = ");
scanf("%d",&b);

printf("\n c = ");
scanf("%d",&c);

printf("\nEnterd Values are : a=%d b=%d c=%d",a,b,c);

printf("\nQuadratic Equation Calculation:");

D=((b*b)-(4*a*c));

printf("\nValue of Normal D= %d ",D);
D1=abs(D);
D1=sqrt(D1);

printf("\nValue of Squared D= %.3f ",D1);

if(D>0)
{ //Multiple Roots
printf("\nReal & Multiple Roots");


x1=((b+D1)/(2*a));

x2=((b-D1)/(2*a));

printf("\n\nRoots are X1=%.3f X2=%.3f ",x1,x2);

}
else if(D==0)
{ //Single Root
printf("\nReal & Single Roots");

x1=((b)/(2*a));

printf("\n\nRoots are X1=%.3f",x1);

}
else
{ //Imaginary Part

printf("\nImaginary Roots");

printf("\nX1=(%d+%.3fi)/2*%d",b,D1,a);

printf("\nX2=(%d-%.3fi)/2*%d",b,D1,a);

}

getch();
}



Sunday, November 2, 2014

Program to print square and cube of any number in C.



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

/* program to print a square and cube of any number */

#include<stdio.h>
#include<conio.h>
void main()
{
int a,sq,cu;

printf("\nEnter a number:");
scanf("%d",&a);
sq=a*a;
cu=a*sq;

printf("\n--------------------");
printf("\n\t Number:%d",a);
printf("\n\t Square:%d",sq);
printf("\n\t Cube  :%d",cu);

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

getch();
}

program to print square and cube of numbers between a given range by user in C.



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

/* program to print square and cube of numbers between range*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sq,cu,br,ij;

printf("\nEnter Start number:");
scanf("%d",&br);
printf("\nEnter End number:");
scanf("%d",&ij);
printf("\n--------------------");

for(i=br;i<=ij;i++)
{
sq=i*i;
cu=i*sq;
printf("\n\t Number:%d",i);
printf("\n\t Square:%d",sq);
printf("\n\t Cube  :%d",cu);

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

}

getch();
}