Search This Blog

Loading...

Sunday, April 26, 2015

Display the characters and ascii values from 0 to 255




#include< stdio.h >
void main()
{
 int i=0;
 clrscr();
  while(i<=255)
 {
 printf("\nAscii value of %c = %d",i,i);
 i++;
 }
  getch();
   }

 The above program will display the characters with ascii values starting from 0 to 255.The problem is that all the displayed lines will  not be visible as the screen can't accommodates all the 256 lines.



   #include< stdio.h>
void main()
{
 int i=0;
 clrscr();
  while(i<=255)
 {
 printf("\nAscii value of %c = %d",i,i);
 if((i+1)%20==0)
 {
 printf("\nPress any key to continue.....");
 getch();
 clrscr();
 }
 i++;
 }
  getch();
   }

Sunday, March 29, 2015

Two Patterns using BlueJ Program


Two patterns as given below will be printed using BlueJ program.
The patterns are:

e
ed
edc
edcb
edcba

and

a c e g
i k m
o q
s

First pattern program.

class A
{
 public void showPattern()
 {
 int i,j,x;
 for(i=0;i<=4;i++)
 {
  x=101;
  for(j=0;j<=i;j++)
  {
  System.out.print((char)x);
  x--;
  }
  System.out.println();
  }
  }
   public static void main(String args[])
  {
   A ob=new A();
   ob.showPattern();
   }
   }

   Second pattern program


class A
{
 public void showPattern()
 {
 int i,j,x=97;
 for(i=0;i<=3;i++)
 {
  
  for(j=i;j<=3;j++)
  {
  System.out.print((char)x);
  x=x+2;
  }
  System.out.println();
  }
  }
   public static void main(String args[])
  {
   A ob=new A();
   ob.showPattern();
   }
   }

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner