Sunday, July 14, 2013

write a program to print following number pattern ?

1 2 3 4
  2 3 4
     3 4
        4
Program:
#include<stdio.h>
#include<conio.h>

void main()
{
   int r, p, k,g=0,h=1;
   clrscr();
   printf("\n enter the no of row");
   scanf("%d", &r);
   for ( k = r ; k >= 1 ; k-- )
   {
       for ( p = 1 ; p <= g; p++ )
       printf(" ");
       g++;
       for ( p = h;p <=r ; p++)
       printf("%d", p);
       h++;

       printf("\n");
   }

   getch();
}
 
Output:
image
{ Read More }


Saturday, July 13, 2013

write a program to print following number pattern ?

4 3 2 1
  3 2 1
    2 1
      1
Program:
#include<stdio.h>
#include<conio.h>

void main()
{
   int r, p, k,g=0;
   clrscr();
   printf("\n enter the no of row");
   scanf("%d", &r);
   for ( k = r ; k >= 1 ; k-- )
   {
       for ( p = 1 ; p <= g; p++ )
       printf(" ");
       g++;
       for ( p = r;p >0 ; p --)
       printf("%d", p);
       r--;

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

Output:
image
{ Read More }


write a program to print following number pattern ?

     1
    12
  123
 1234
12345
Program:
#include<stdio.h>
#include<conio.h>

void main()
{
   int r, p, k,g=0,h=1;
   clrscr();
   printf("\n enter the no of row");
   scanf("%d", &r);
   for ( k = r ; k >= 1 ; k-- )
   {
       for ( p = --r; p >0; p--)
       printf(" ");

       for ( p = 1;p <=h ; p++)
       printf("%d", p);
       h++;

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

Output:
image

{ Read More }


write a program to print following number pattern ?

1
23
456
78910
Program:
#include<stdio.h>
#include<conio.h>

void main()
{
   int r, p, k,h=1;
   clrscr();
   printf("\n enter the no of row");
   scanf("%d", &r);
   for ( k = 1 ; k <= 5 ; k++ )
   {
       for ( p =1; p <=k; p++,h++)
       printf("%d", h);

       printf("\n");
   }

   getch();
}

Output:
image


{ Read More }


Thursday, July 11, 2013

write a program to print the following ‘*’ pattern ?

    *******
     *****
      ***
       *

Program:
#include<stdio.h>
#include<conio.h>

void main()
{
  int n,r,a,p;
  clrscr();
  printf(" enter the no of rows  ");
  scanf("%d",&n);
  for(r=1;r<=n; r++)
  {
   for(p=r; p>=1; p--)
    printf(" ");
   for(a=1; a<=n-r;a++)
    printf("*");
   for(a=n-r-1; a>=1; a--)
    printf("*");
   printf("\n");
  }
  getch();
}

Output:
image

{ Read More }


Write a Program to print the following * pattern?

      *
    ***
  ***** 
*******                              
Program:
#include<stdio.h>
#include<conio.h>

void main()
{
  int n,r,a,p;
  clrscr();
  printf("enter the no of rows ");
  scanf("%d",&n);
  for(r=1;r<=n; r++)
  {
   for(p=n-r; p>=1; p--)
       printf(" ");
   for(a=r; a>=1; a--)
        printf("*");
   for(a=r; a>1; a--)
        printf("*");
   printf("\n");
  }
  getch();
}
Output:
image
{ Read More }


Tuesday, July 2, 2013

Write a program to find square root of the given ni without using sqrt function ?

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

void main()
{
const float x=0.00001;
float g=1.0,no;
clrscr();
printf("\n enter the number");
scanf("%f",&no);
do
{
g=(no/g+g)/2.0;
}
while(abs(g*g-no)>=.00001);
printf("\n the square root of %.0f is %.4f",no,g);
getch();
}



Output:

 


{ Read More }