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

Tuesday, December 16, 2014

Program to print number pattern using for loop in C.(Pattern 9)


Number Pattern 9 codeboxc


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

/*program to print number pattern  by for loop

            1
          12
        123
      1234
    12345

*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,k;
i=1;
clrscr();

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

for(i=1;i<=n;i++)
{
        for(j=n;j>i;j--)
        {
        printf(" ");
        }

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

        printf("%d",k);
        }
printf("\n");

}

getch();

}



Sunday, December 14, 2014

Program to print number pattern using while loop in C.(Pattern 4)




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

/*program to print star pattern square box by while loop

  11111
  22222
  33333
  44444
  55555

*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
i=1;
clrscr();

printf("\nEnter value of n :");
scanf("%d",&n);

while(i<=n)
{j=1;
        while(j<=n)
        {
        printf("%d",i);
        j++;
}

printf("\n");
i++;
}

getch();
}


Thursday, December 11, 2014

Program to print number pattern square box by do while loop in C. (Pattern 2)


Number Pattern 2


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

/*program to print number pattern square box by do while loop

  1
  12
  123
  1234
  12345

*/ 155223 

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
i=1;
clrscr();

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

do
{j=1;
        do
        {
        printf("%d",j);
        j++;
}
while(j<=i);

printf("\n");
i++;
}
while(i<=n);

getch();
}



Program to print number pattern square box by for loop in C. (Pattern 2)


Number Pattern


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

/*program to print star pattern square box by for loop

  1
  12
  123
  1234
  12345

*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
i=1;
clrscr();

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

for(i=1;i<=n;i++)
{
        for(j=1;j<=i;j++)
        {
        printf("%d",j);
        }

printf("\n");

}
getch();
}



Sunday, December 7, 2014

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


sum of even series using while loop


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

/*program to calculate sum of the series
2+4+6+8.......+n
even 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("\nEven Number Series ");

printf("\nSeries= ");

i=1;
while(i<=num)
{

if(i%2==0)      //modulus operator
{
printf(" + %d ",i);
sum=sum+i;
}
i++;                //increment operator
}
printf("\n\nSum of series= %d",sum);

getch();
}



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


sum of cube series


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

/*program to calculate sum of the series 
(1*1*1)+(2*2*2)+(3*3*3)+(4*4*4)+.......+(n*n*n).
cube number series. 
without using power function.
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("\nCube Number Series ");

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

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

getch();
}

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();
}

Friday, December 5, 2014

Program to print factorial of any input number using while loop in C.



factorial


Code Box

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

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

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

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\nFactorial of %d is:",num);
printf("\n-----------------------------\n");

while(num>=1)
{
if(num==0)
{
printf("\n1"); //factorial of 0 is 1
break;
}
fact=fact*num;
num--;
}

printf("\n%.0f",fact);

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

getch();
}


Program to print factorial of any input number using for loop in C.



factorial


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

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

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

float fact;

/* If we take fact as integer, it can not be able
to store factorial of value greater than 9 */

fact=1.0;

clrscr();

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\nFactorial of %d is:",num);
printf("\n-----------------------------\n");


if(num==0)
{
printf("\n1"); //factorial of 0 is 1
}
else
{
for(i=1;i<=num;i++)
{
fact=fact*num;
num--;
}
}
printf("\n%.0f",fact);

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

getch();
}

Program to find input number is prime or not with special case in C.


prime number


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

/*Program to find input number is prime or not*/

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,c;
c=0; //counter
clrscr();

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");


if(num==0)
{
printf("\nZero entered!!"); //Zero case
}
else
{
/*Prime finder */
for(i=2;i<=(num/2);i++)
{ /*start from 2 because every number is divisible by 1 */
/* i<=(num/2) because any number can be completely divisible by only half or less than itself.*/
if(num%i==0)
{
c=1;
}
}

/*Prime checker */
if(c==0)
{
printf("\n%d is prime",num);
}
else{
printf("\n%d is not a prime",num);
}

}

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

getch();
}



Program to find input number is prime or not using while loop in C.


prime number


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

/*Program to find input number is prime or not*/

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,c;
c=0; //counter
clrscr();

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");

i=2;
/*start from 2 because every number is divisible by 1 */

/*Prime finder */
while(i<num)
{
if(num%i==0)
{
c=1;
}
i++;
}

/*Prime checker */
if(c==0)
{
printf("\n%d is prime",num);
}
else{
printf("\n%d is not a prime",num);
}

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

getch();
}



Program to check input number is perfect number or not using while loop in C.


perfect number


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

/*Program to check input number is perfect number or not*/

/*Perfect number: sum of all it's factors is equal to number itself */

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

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\nFactores of %d is:",num);
printf("\n-----------------------------\n");

while(i<num)
{

if(num%i==0)
{
printf(" %d ",i);
sum=sum+i;
}

i++;
}

printf("\nSum of factors is: %d",sum);

if(num==sum)
{
printf("\n%d is a perfect number",num);
}
else
{
printf("\n%d is not a perfect number",num);
}

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

getch();
}




Thursday, December 4, 2014

Program to print table of any input number along with sum of all values using for loop in C.

table sum

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

/*Program to print table of any input number along with sum of all values */

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

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\nTable of %d is",num);
printf("\n---------------------------------------\n");

for(i=1;i<=10;i++)
{
mul=num*i;
printf("| %d ",mul);
sum=sum+mul;
}
printf("\n--------------------------------------");

printf("\nSum of table is : %d",sum);

getch();
} 

Program to print table of any input number using while loop in C.




Code Box
--------------------------------------------
/*Program to print table of any input number*/

#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,mul;
i=1;
clrscr();

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\nTable of %d is",num);
printf("\n---------------------------------------\n");

while(i<=10)
{
if(num==0)
{
printf("\nZero entered");
break;
}
mul=num*i;
printf("\n %d x %d = %d ",num,i,mul);

i++;
}

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

getch();
} 

Program to print table of any input number using for loop in C.





Code Box
---------------------------------------------
/*Program to print table of any input number*/

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

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

clrscr();  //for clear screen

printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\nTable of %d is",num);
printf("\n---------------------------------------\n");

for(i=1;i<=10;i++)
{
if(num==0)
{
printf("\nZero entered");
break;
}
mul=num*i;
printf("\n %d x %d = %d ",num,i,mul);
//print in format num x i=mul
}

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

getch();
} 

Sunday, November 30, 2014

Program to enter hours and print numbers of days and remaining hours and convert remaining hours into minutes in C.




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

/*Program to enter hours and print numbers of days and remaining hours and convert remaining hours into minutes */

#include<stdio.h>
#include<conio.h>
void main()
{

float hours,rhours,min;
/*hours for hours enter by User and rhours for remaining hours */

int days,h;
/*For numbers of Day */

clrscr();

printf("\n\tHours to Day Converter");
printf("\n\tEnter Hours :");
scanf("%f",&hours);

h=hours;

printf("\n\tHours:%d",h);
min=hours-h;
printf("\n\tRemaining Hours:%.2f",min);

min=(min*60);
printf("\n\tMinutes:%.2f",min);


rhours=h%24;

/*Modulus operator provide us the remainder after Division which is remaining hours */

days=(int)hours/24;
/*Division operator to calculate Days as we know 24 hours means 1 Day */

printf("\n\tNumber of Days : %d",days);
printf("\n\tRemaining Hours: %f",rhours);

getch();
}

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();
}



Saturday, November 29, 2014

Program to enter hours and print numbers of days and remaining hours in C




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

/*Program to enter hours and print numbers of days and remaining hours */

#include<stdio.h>
#include<conio.h>
void main()
{

int hours,rhours;
/*hours for hours enter by User and rhours for remaining hours */

int days;
/*For numbers of Day */

clrscr();

printf("\n\tHours to Day Converter");
printf("\n\tEnter Hours :");
scanf("%d",&hours);

rhours=hours%24;
/*Modulus operator provide us the remainder after Division which is remaining hours */

days=hours/24;
/*Division operator to calculate Days as we know 24 hours means 1 Day */

printf("\n\tNumber of Days : %d",days);
printf("\n\tRemaining Hours: %d",rhours);


getch();
}