About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Saturday, December 10, 2011

Pattern Printing 16



#include

main()
{
    int n, c, k;
    clrscr();
    printf("Enter number of rows::");
    scanf("%d",&n);

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

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

---------------------------------------
output:-
Enter number of rows::6
1
1  2
1  2  3
1  2  3  4
1  2  3  4  5
1  2  3  4  5  6

















Pattern Printing 15



#include

main()
{
    int number = 1, n, c, k;
    clrscr();
    printf("Enter number of rows::");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++ )
    {
        for( k = 1 ; k <= c ; k++ )
        {
            printf("%d ", number);
            number++;
        }

        number = 1;

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

---------------------------------
output:-

Enter number of rows::5
1
1  2
1  2  3
1  2  3  4
1  2  3  4  5


















Pattern Printing 14


#include

main()
{
    int n, c, k;
    clrscr();
    printf("Enter number of rows::");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++ )
    {
for( k = 1 ; k <= c ; k++ )
{
   printf("* ");
}

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

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

output:-

Enter number of rows::7
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
















Pattern Printing 13



#include

main()
{
    int n, c, k, temp;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    temp = n;

    for ( c = 1 ; c <= n ; c++ )
    {
        for( k = 1 ; k <= temp ; k++ )
            printf("* ");

        temp--;

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

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

output:-
Enter number of rows::5
* * * * *
* * * *
* * *
* *
*


















Pattern Printing 12



#include

main()
{
    int n, c, k, space, count = 1;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    space = n;

    for ( c = 1 ; c <= n ; c++)
    {
        for( k = 1 ; k < space ; k++)
           printf(" ");

        for ( k = 1 ; k <= c ; k++)
        {
            printf("*");

            if ( c > 1 && count < c)
            {
                 printf("A");
                 count++;
            }
        }

        printf("\n");
        space--;
        count = 1;
    }
    getch();
    return 0;
}


--------------------------------
output:-

Enter number of rows::5
        *
      *A*
    *A*A*
  *A*A*A*
*A*A*A*A*


















Pattern Printing 11



#include

main()
{
    int n, c, k;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++)
    {
        for ( k = 1 ; k <= c ; k++ )
            printf("*");

        printf("\n");
    }

    for ( c = n - 2 ; c >= 0 ; c-- )
    {
        for ( k = c ; k >= 0 ; k-- )
            printf("*");

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


--------------------------------
output:-
Enter number of rows::5
*
**
***
****
*****
****
***
**
*














Pattern Printing 10


#include

void main()
{
    int n, c, k;

    clrscr();
    printf("Enter number of rows::");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++ )
    {
        for( k = 1 ; k <= c ; k++ )
            printf("%d", c);

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

----------------------------------
output:-

Enter number of rows::8
1
22
333
4444
55555
666666
7777777
88888888















Pattern Printing 9



#include

main()
{
    int n, c, k, space;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    space = n;

    for ( k = 1 ; k <= n ; k++ )
    {
        for ( c = 1 ; c < space ; c++ )
            printf(" ");

        space--;

        for( c = 1 ; c <= k ; c++ )
            printf("*");

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

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

output:-
Enter number of rows
7
           *
         **
       ***
     ****
   *****
  ******
*******















Pattern Printing 8

#include


void main()
{
    int n, c, k, space, r;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    space = 1;
    r = n-1;

    for( c = 1 ; c <= 2*n - 1 ; c++ )
         printf("*");

    printf("\n");

    for ( k = 2 ; k <= n ; k++ )
    {

        for( c = 1 ; c <= r ; c++ )
            printf("*");

        for ( c = 1 ; c <= space ; c++ )
            printf(" ");

        space = 2*k-1;

        for( c = 1 ; c <= r ; c++ )
            printf("*");
        r--;

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


--------------------------------------
output:-
Enter number of rows
7
*************
******  ******
*****      *****
****          ****
***              ***
**                  **
*                      *















Pattern Printing 7



#include

void main()
{
      int n, c, d, num = 1, space;
      clrscr();
      printf("Enter the number of rows::");
      scanf("%d",&n);

      space = n - 1;

      for ( d = 1 ; d <= n ; d++ )
      {
          num = d;

          for ( c = 1 ; c <= space ; c++ )
              printf(" ");

          space--;

          for ( c = 1 ; c <= d ; c++ )
          {
              printf("%d", num);
              num++;
          }
          num--;
          num--;
          for ( c = 1 ; c < d ; c++)
          {
              printf("%d", num);
              num--;
          }
          printf("\n");

      }
      getch();

}


-----------------------------------
output:-
Enter the number of rows::6
     1
    232
   34543
  4567654
 567898765
67891011109876

















Pattern Printing 6



#include

main()
{
      int n, c, k, x = 1;
      clrscr();
      printf("Enter number of rows::");

      scanf("%d", &n);

      for ( c = 1 ; c <= n ; c++ )
      {
          for ( k = 1 ; k <= c ; k++ )
          {
              printf("%d", x);
              x++;
          }

          x--;

          for ( k = 1 ; k <= c - 1 ; k++ )
          {
              x--;
              printf("%d", x);
          }

          printf("\n");
          x = 1;
      }
      getch();
      return 0;
}

--------------------------------
output:-
Enter number of rows::6
1
121
12321
1234321
123454321
12345654321

















Pattern Printing 5



#include
#include

main()
{
      char string[100];
      int c, k, length;
      clrscr();

      printf("Enter a string\n");
      gets(string);

      length = strlen(string);

      for ( c = 0 ; c < length ; c++ )
      {
          for( k = 0 ; k <= c ; k++ )
          {
               printf("%c", string[k]);
          }
          printf("\n");
      }
      getch();
      return 0;
}


-----------------------------
output:-

Enter a string
amit singh
a
am
ami
amit
amit
amit s
amit si
amit sin
amit sing
amit singh












Pattern Printing 4



#include

main()
{
      int n, c, k, num = 1;
      clrscr();
      printf("Enter the number of rows:");
      scanf("%d", &n);

      for ( c = 1 ; c <= n ; c++ )
      {
          for ( k = 1 ; k <= c ; k++ )
          {
              printf("%d", num);

              if ( num == 0 )
                 num = 1;
              else
                 num = 0;
          }
          printf("\n");
      }
      getch();
      return 0;
}

-------------------------------
output:-
Enter the number of rows:5
1
01
010
1010
10101


















Pattern Printing 3



#include

main()
{
      char ch = 'A';
      int n, c, k, space = 0;
      clrscr();
      printf("Enter Number of Rows..");

      scanf("%d", &n);

      for ( k = n ; k >= 1 ; k-- )
      {
          for ( c = 1 ; c <= space ; c++)
              printf(" ");

          space++;

          for ( c = 1 ; c <= k ; c++ )
          {
             printf("%c ", ch);
             ch++;
          }

          printf("\n");
          ch = 'A';
      }
      getch();

      return 0;
}

--------------------------------
Output:-
Enter Number of Rows..6
A B C D E F
 A B C D E
  A B C D
   A B C
    A B
     A

















Pattern Printing 2


#include
#include

main()
{
    int n, c, k;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++ )
    {
        for( k = 1 ; k <= c ; k++ )
            printf("*");

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

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

output:-

Enter number of rows
7
*
**
***
****
*****
******
*******


Pattern Printing 1


#include
#include

void main()
{
int row, c, n, temp;

printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);

temp = n;

for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
{
printf(" ");
}

temp--;

for ( c = 1 ; c <= 2*row - 1 ; c++ )
{
printf("*");
}
printf("\n");
}

getch();
}
-------------

Output:-

Enter the number of rows in pyramid of stars you wish to see 6
     *
    ***
   *****
  *******
 *********
***********

Tuesday, July 26, 2011

***sorting the Array***


//sorting the Array


import java.io.*;
import java.util.*;
class SortingArray
{
public static void main(String aa[])throws IOException
{
int arr[]=new int[10];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter 10 elements in Array...");
for(int i=0;i<10;i++)
{
arr[i]=Integer.parseInt(br.readLine());


}


Arrays.sort(arr);


System.out.println("Sorted elements in Array...");
for(int i=0;i<10;i++)
{
System.out.println(" "+arr[i]);


}



}
}


Output


--Addition and Multiplication of Two Matrices A and B--


//Addition and Multiplication of Two Matrices A and B


import java.io.*;


class MatrixAddition
{
public static void main(String aa[]) throws Exception
{
int A[][]=new int[3][3];
int B[][]=new int[3][3];
int C[][]=new int[3][3];


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please Enter 9 Elements in Matrix A:-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
A[i][j]=Integer.parseInt(br.readLine());


}
}


System.out.println("Please Enter 9 Elements in Matrix B:-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
B[i][j]=Integer.parseInt(br.readLine());


}
}

//Addition of A and B
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=A[i][j]+B[i][j];


}
}


System.out.println("Addition of Two Matrices is :-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}




//Multiplication of A and B

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
C[i][j]=0;
for(int k=0;k<3;k++)
{
C[i][j]=A[i][k]*B[k][j]+C[i][j];
}
}
}


System.out.println("Multiplication of Two Matrices is :-");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+C[i][j]);
}
System.out.println("");
}











}
}
Output




**Demo of Abstract Class and Methods**


//Demo of Abstract Class and Methods


abstract class A
{
abstract void show();
void display()
{
System.out.println("This is display() method of Abstract class A...");
}
}


class B extends A
{
void show()
{
System.out.println("This is Overridden Method show() of class A in class B...");
}

}


class AbstractDemo
{
public static void main(String aa[])
{
B b=new B();
b.show();
       b.display();
}
}


Output




Monday, July 25, 2011

***Swapping of two numbers***


//Swapping of two numbers
public class Swapping
{
public static void swap(int i,int j)
{
    int temp=i;
    i=j;
    j=temp;
    System.out.println("After swapping i = " + i + " j = " + j);
  }
  
public static void main(String[] args)
{
    int i=1;
    int j=2;
  
  System.out.println("Before swapping i="+i+" j="+j);
    swap(i,j);
  
  }
}


Saturday, July 23, 2011

***Creating Shapes in Applet***


import java.applet.*;
import java.awt.*;

public class  ShapColor extends Applet
{
  int x=300,y=100,r=50;

  public void paint(Graphics g)
  {
  g.setColor(Color.red);  //Drawing line color is red
  g.drawLine(3,300,200,10);
  g.setColor(Color.magenta);
  g.drawString("Line",100,100);

  g.drawOval(x-r,y-r,100,100);
  g.setColor(Color.yellow);  //Fill the yellow color in circle
  g.fillOval( x-r,y-r, 100, 100 );
  g.setColor(Color.magenta);
  g.drawString("Circle",275,100);
 
  g.drawRect(400,50,200,100);
  g.setColor(Color.yellow);  //Fill the yellow color in rectangel
  g.fillRect( 400, 50, 200, 100 );
  g.setColor(Color.magenta);
  g.drawString("Rectangle",450,100);
  }
}


***Palindrome Checking for Numbers***


import java.io.*;

public class Palindrome
{
public static void main(String [] args)
{
  try
{
  BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
  System.out.println("Enter number");
  int num= Integer.parseInt(object.readLine());
  int n = num;
  int rev=0;
  System.out.println("Number: ");
  System.out.println(" "+ num);
  for (int i=0; i<=num; i++)
{
  int r=num%10;
  num=num/10;
  rev=rev*10+r;
  i=0;
  }
  System.out.println("After reversing the number: "+ " ");
  System.out.println(" "+ rev);
  if(n == rev)
{
  System.out.print("Number is palindrome!");
  }
  else
{
  System.out.println("Number is not palindrome!");
  }
  }
  catch(Exception e)
{
  System.out.println("Out of range!");
  }
  }
}


***A Simple Applet Program***


// -------------PersonApplet.java----------

import java.awt.*;
import java.applet.Applet;

public class PersonApplet extends Applet
{

        public void paint(Graphics g)
       {

// draw some people!
g.setColor(Color.red);
drawPerson(g, 50, 380, 200);
g.setColor(Color.cyan);
drawPerson(g, 100, 380, 200);
g.setColor(Color.blue);
drawPerson(g, 150, 380, 300);


}

private void drawPerson(Graphics g, int x, int y, int h)
       {

// Draw head (about a 1/4 of the height in proportion)
g.fillOval(x-h/8, y-h, h/4, h/4);

// Draw body
g.drawLine(x, y-3*h/4, x, y - h/4);

// Draw legs
g.drawLine(x, y-h/4, x-h/8, y);
g.drawLine(x, y-h/4, x+h/8, y);

// Draw arms
g.drawLine(x, y-5*h/8, x-h/8, y-3*h/4);
g.drawLine(x, y-5*h/8, x+h/8, y-3*h/4);

}

}



Thursday, April 7, 2011

Write to me...

My Email Ids are:-
amit_thakur744@yahoo.co.in
amitthakur744@gmail.com