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

Tuesday, December 16, 2014

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

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

/*program to print number pattern  by do while 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);

do
{j=n;
k=1;
        do
        {
        printf(" ");
        j--;
}
while(j>=i);

        do
        {

        printf("%d",k);
k++;
        }
while(k<=i);
printf("\n");
i++;
}
while(i<=n);
getch();
}



Monday, December 15, 2014

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

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

/*program to print number pattern by do while loop

  5
  54
  543
  5432
  54321

*/

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

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

i=n;
do
{j=n;
        do
        {
printf("%d",j);
        j--;
}
while(j>=i);
printf("\n");
i--;
}
while(i>=1); 

getch();

}

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


Number pattern 7 codeboxc


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

/*program to print number pattern by while loop

  1
  21
  321
  4321
  54321

*/

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

printf("\nEnter a value: ");
scanf("%d",&n);
i=1;

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

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

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


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


Number Pattern


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

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

  1
  22
  333
  4444
  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<=i)
        {
        printf("%d",i);
        j++;
}

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

getch();

}

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



Number Pattern


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

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

  1
  22
  333
  4444
  55555

*/

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

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

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


getch();

}



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



Number pattern



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

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

  1
  22
  333
  4444
  55555

*/

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

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

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

printf("\n");

}

getch();

}


--Explanation--------------------------------------











Program to print ASCII values of all characters in C.



Character to ASCII


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

/*program to print ASCII values of all Characters*/
/* We know the range of character is from -127 to 128 */

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char ch;
clrscr();

printf("\n----CHARACTER VALUE OF ASCII-----\n");

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

ch=i;    //Integer to Character

printf("%d = %c | ",i,ch);

}

getch();
}


Program to convert Character value into a ASCII value in C.


Character to ASCII


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

/*program to convert Character value into ASCII value */

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char ch;
clrscr();

printf("\n----CHARACTER TO ASCII-----");
printf("\nEnter a Character:");
scanf("%c",&ch);

i=ch;

printf("\nASCII vallue of Character %c is %d ",ch,i);

getch();
}



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

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


program to calculate sum of the series



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

/*program to calculate sum of the series 
1+2+3+4+.......+n
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("\nSeries= ");
for(i=1;i<=num;i++)
{
printf(" + %d ",i);
sum=sum+i;
}
printf("\n\nSum of series= %d",sum);

getch();
}

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


sum of special series

sum of special series formula



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

/*Program to calculate sum of series

 1/(1*2)+1/(2*3)+1/(3*4)+.......+1/((n-1)*n)

 where n is the value entered by user.

 =>Explicit type conversion
 =>Nested loop
*/

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


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


printf("\nSeries=");

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

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

mul=i*(i+1);
printf(" +1/(%d*%d) ",i,i+1);


sum=sum+(float)1/mul;  //Explicit type conversion
}

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

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

getch();
}

Saturday, December 6, 2014

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


factorial sum

factorial series



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

/*Program to calculate sum of series

 1/1!+1/2!+1/3!+.......+1/n!

 where n is the value entered by user.

 =>Explicit type conversion
 =>Nested loop
*/

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,j;
float sum,mul;
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; //factorial
}

sum=sum+(float)1/mul;  //Explicit type conversion
}

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.





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



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

 where n is the value entered by user.

 =>Explicit type conversion

*/

#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+(float)1/i; //Explicit type conversion

}

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


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


factorial of number


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");

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

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

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

getch();
}



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