Tuesday, September 30, 2008

How to Pass a Function Pointer in C++

Sample C++ code snippet...


void PassPtr(int (*ptr2Func)(float, char, char))
{
float result = ptr2Func(12, 'a', 'b'); // call using function pointer

cout << result << endl;
} /* is a pointer to a function which returns an int and takes a float and two char */

void Pass_A_Function_Pointer()
{
cout << endl << "Executing 'Pass_A_Function_Pointer'" << endl;
PassPtr(&DoIt);
} // execute example code - 'DoIt' is a suitable function

Friday, September 19, 2008

Smallest C code snippet to find whether number is odd or even

/*C program to find whether number is odd or even*/

void main()
{
int num;
scanf("%d",&num);
(num&1)= =1?printf("ODD"):printf("EVEN");
}

C program to print count of lines, words and characters in a text file

C program to print count of lines, words and characters in a text file

#include< stdio.h >
#include< stdlib.h >

void main(int argc,char argv[])
{
int char_count=0,line_count=0,word_count=0;
FILE *fp;
char ch;

//char w='\n';
//sprintf("%d",w);
//if(argc!=1)
// printf("One argument is needed\n");
//fp=fopen("argv[1]","r");

fp=fopen("c:\\kk.txt","r");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
{
break;
}
char_count++;
if(ch==' ')
word_count++;
if(ch=='\n')
{
line_count++;
word_count++;
}
}
printf("word count =%d\n Line count =%d\n char countd\n",word_count,line_count,char_count);

}

Monday, September 15, 2008

C & C++ FAQ's

1. What is a class?


2. What is an object?


3. Define what an attribute or property of an object is.


4. Define what an object behavior is.


5. Describe the methods and attributes of a Card class to represent a card used in card games.


6. Define inheritance.


7. Describe the benefits of inheritance.


8. Which of these is a base class: Vehicle or Minivan?


9. Which is an example of inheritance: an Engine class and a Diesel class, or an Engine class and a Car class?


10. What is a business object?


11. What is a characteristic?


12. What is a class definition?


13. What is an argument list?


14. What is a return value?


15. If Engine were a class in Java, how would you define an instance of it?


16. If Engine were a class in C++, how would you define an instance of it?


17. What is a constructor?


18. What is a destructor?


19. What is garbage collection?


20. How do you access members of an object?


21. Define encapsulation.


22. Define polymorphism.


23. Define overloading.


24. Define binding.


25. Define runtime polymorphism.


26. What is a virtual function?


27. How would you define a virtual method in C++?


28. How would you define a virtual method in Java and C#?


29. Define method overloading.


30. Compare Public, Protected, and Private members of a class.


31.
Define simple inheritance.


32.
Define multiple inheritance.


33.
What is the "Diamond Problem" of multiple inheritance?


34.
Define level inheritance.


35.
What is the maximum number of levels for level inheritance?


36.
What are the terms typically used to refer to the parent and child classes in C++ and Java?


37.
Define abstraction.


38.
What is the difference between functionality and function?


39.
What is an abstract method?


40.
Define an abstract class.


41.
What is data decomposition?


42.
What is an iconic description?


43.
Define pseudo code.


44.
What is an entity?


45.
What is an entity relationship?


46.
What is a many-to-many relationship?


47.
Define a leveling diagram.


48.
What is a class diagram?


49.
What is an internal model?


50.
What is an external model?


51.
What is the "is a" test?


52.
What is the "has a" test?


53.
Define collaboration.


54.
What is UML?


55.
What is a sequence diagram?


56.
What is a collaboration diagram?


57.
What is a message?


58.
What is association?


59.
What is self-collaboration?


60.
What is a Class Responsibility Collaborator diagram?


61.
What is an actor?


62.
What is an SME?


63.
What is an Essential Use Case?


64.
What is a System Case?


65.
What are business rules?


66.
What is a User Interface diagram?


67.
What is a User Interface-Flow diagram?


68.
What is a Change Case?


69.
What is an interface?


70.
Describe some of the basic units of project management.


71.
Describe three common errors when using abstraction.


72.
What is a framework?


73.
Describe three basic categories of reuse.


74.
How are approaches to OO programming analogous to nouns and verbs?


75.
How can a hierarchy be morphed?


76.
When might you use multiple inheritance?


77.
What is early binding?


78.
What is late binding?


79.
Do UML sequence diagrams show flow control?


80.
What is a finalize method in Java?


81.
What is the difference between static and non-static class members?


82.
What is the Java syntax to declare class Derived from class Base?


83.
What is the C++ syntax to declare class Derived from class Base?


84.
What is the C# syntax to declare class Derived from class Base?


85.
What does the final keyword in Java mean when applied to a class?


86.
Is Java a compiled or interpreted language?


87.
Is C++ a compiled or interpreted language?


88.
Is C# a compiled or interpreted language?


89.
Which language supports multiple inheritance: Java, C++, or C#?


90.
Which language offers the best portability to other platforms: Java, C++, or C#?


91.
Describe one advantage and disadvantage of garbage collection.


92.
Which language provides the easiest access directly to memory?


93.
Which languages support interfaces syntactically: Java, C++, or C#?


94.
Which languages support templates or generics: Java, C++, or C#?


95.
What are the three editions of Java?


96.
What is the JVM?


97.
What is the CLR?


98.
What has the smallest footprint, memory-wise: Java, C++, or C#?


99.
What was one of the first stored-program computer systems?


100.
Where did the term "bug" come from?


Answers
1.
A class is a set of methods and data items combined in a single entity. It provides some service or does some work and serves as a functionality package.

2.
An object is an instance of a class. A class is essentially a data type, and an object is a variable of that data type.

3.
An attribute or property is a piece of data in a class. It has a value at any given time and may be readable, writable, or both.

4.
Object behavior defines how an object works under certain operations.

5.
Attibutes: Suit, Value, FaceUp
Methods: GetSuit, SetSuit, GetValue, SetValue, IsFaceUp, Flip

6.
Inheritance means that a class is based upon the methods and attributes of an existing class.

7.
Code reuse

8.
Vehicle, because a minivan "is a" vehicle—the minivan is derived from vehicle.

9.
Engine and Diesel, because Diesel "is a" type of engine. A Car "has a(n)" engine, which describes containment, not inheritance.

10.
A business object is a class used by a business system or application, such as an order form.

11.
A characteristic is an attribute or method that distinguishes two classes.

12.
A class definition defines attributes and methods that are members of the class.

13.
An argument list is a list of data items passed to a method or function for it to do its job.

14.
A return value is a value that a method returns as its output or result. Return values are optional.

15.
Engine anEngine = new Engine();

16.
Engine anEngine;

17.
A constructor is a special method that initializes the attributes of a class.

18.
A destructor is a special method that releases any resources (such as memory) from an object instance. Java does not implement "true" destructors, while C++ does because Java performs garbage collection while C++ doesn't (and garbage collection is not guaranteed to run before the program terminates).

19.
Garbage collection is the ability of a language to automatically remove objects created in memory when the last reference or use of the object goes out of scope or is no longer needed.

20.
In Java, C++, and C#, you use the dot (.) operator. C++ also uses the arrow (->) operator if you have a pointer to an object.

21.
Encapsulation is the grouping of concepts or behaviors into a class. It defines how the class behaves, without offering details as to how it implements that behavior.

22.
Polymorphism means that something has many shapes and that something is a method of an object-oriented programming language. In programming terms, a thing is the name of a method and a shape is the behavior performed by a method. Polymorphism means that one or more methods with the same name exist for many behaviors.

23.
Overloading is another one of those terms you hear used in conjunction with polymorphism. Overloading means that two or more methods are defined using the same name, but with different argument list.

24.
Binding is the association of a method definition (or function body) with a call to a method, and occurs either at compile time or at runtime. Compile-time or Early binding is used for normal method calls. No time is lost when the program runs because binding is completed when the executable program is created. Runtime or Late binding is implemented using a virtual function, which uses a base reference to point to the type of object that contains the correct method definition.

25.
Run-time polymorphism uses virtual functions to create a standard interface and to call the underlying functions. Those function definitions are bound to function calls during run time.

26.
A virtual function is used to trick the computer into thinking a function is defined, but the function doesn't have to be defined at that moment. Instead, the virtual function can be a placeholder for the real function that is defined in a program. Virtual functions help support run-time polymorphism.

27.
Use the keyword virtual in the declaration of the method, such as Foo:
class Boo {public:virtual void Foo();};

28.
Methods are virtual in Java and C# by default. To create a virtual method without any body in these languages, use the abstract keyword in the declaration of the method.

29.
Method Overloading is a technique to implement polymorphism by defining two or more methods with the same name but different argument list.

30.
Public members are seen by all methods, even ones outside the class. Protected members are seen only to that class and ones derived from it. Private members are seen only by that class, and nothing else.

31.
Simple inheritance occurs when there is one parent-child relationship—that is, one child inherits from one parent.

32.
Multiple inheritance is where there is a multiple parent-child relationship. The child inherits from more than one parent. Java and C# do not support multiple inheritance, but C++ does.

33.
It describes a situation where a single base class (such as Person) contains a data member such as Name, and then two classes are derived from it such as Student and Instructor. Now that Student and Instructor contain a Name member, if we were to create a new class derived from both (such as a TeachingAssistant class), then the object could have two names for what is really one person.

34.
Level inheritance happens when a child inherits from a parent and then becomes a parent itself to a child.

35.
There is no practical limit—if you find a compiler that can't handle 1,000 levels of inheritance, the real problem is that you have a poor design because there are too many levels of inheritance. A rule of thumb is to try and limit things to three levels.

36.
C++ typically uses the terms base class and derived class, while Java typically uses super class and subclass.

37.
Abstraction is a way a programmer of a super class forces a programmer of a subclass to define a behavior.

38.
Programmers distinguish a behavior from instructions used to perform the behavior using the term's functionality and function.

39.
An abstract method does not provide a method body. A class with an abstract method requires derived classes to implement the method body. A class with an abstract method is called an abstract class. Abstract methods are called "pure virtual" methods in C++.

40.
An abstract class is one that has one or more abstract methods. Because of this, you cannot instantiate an object of this type. You must create a derived class that provides the method bodies for the abstract methods, and then you can instantiate the derived class.

41.
Object-oriented programmers decompose each attribute into data and then use data in the corresponding class definition to describe the object. Decomposition is the technique that reduces an attribute into its data components.

42.
An iconic description is a graphic picture of the process. Textual description describes the process in words.

43.
Pseudo code is a combination of English words and programming language syntax that describe in words how a process works. The result is not entirely English, nor a syntactically correct program. It's used to enforce understanding and requirements without actually writing a program.

44.
An entity refers to an individual item, and may be a single piece of data or an object.

45.
Entity relationship (or functional relationship) describes how objects are related or interact with one another.

46.
It defines a relationship between two different types (such as Student and Course) where any single first type (Student) can be related to 1 or more of the second type (Course), and vice versa. For example, one student may be registered in many courses, and a course may have many students.

47.
A leveling diagram depicts an application in layers where the top level has the least amount of detail and is the easiest to understand. Subsequent levels have more detail and are usually the hardest to understand.

48.
A class diagram is an illustration that describes a class, its attributes, and its behaviors.

49.
The internal model describes how an application works behind the scenes.

50.
The external model describes how a person interacts with the application.

51.
The "is a" test asks the question is object A a type of object B. If so, then object A can inherit object B. For example, a Minivan is a type of Vehicle, so Minivan can be derived from Vehicle.

52.
The "has a" test asks the question does object A have an object B. If so, then object A would have a data member of type Object B. For example, a Vehicle has an Engine, so a Vehicle object would have an Engine object as a data member.

53.
Collaboration occurs when two or more things work together or cooperate with each other in order to achieve a common goal. In programming, it means that one class might have methods that call methods from another class.

54.
UML stands for Unified Modeling Language, and is a set of diagramming and text standard to help define a process and classes involved in the process.

55.
A Sequence diagram is a diagram that shows the typical sequence of events for a process.

56.
Collaboration diagrams are used to display basic interaction between classes.

57.
When discussing collaboration, we typically say that a class collaborates with another via a Message. Technically, a message is a function call, so if we say that class A sends a message to class B, we are saying that class A is calling a method in a class B object.

58.
Association means that the two classes need to know how to interact with one another, and is part of the description of collaboration.

59.
Self-collaboration is when a class invokes its own methods.

60.
The Class Responsibility Collaborator (CRC) diagram is intended to be an all-inclusive list of how a single class is to be designed. A CRC diagram lists the class name at the top, and then two columns below for responsibilities and collaborators.

61.
An actor is a person, organization, or anything that might interact with a system. Actors don't need to be persons. If a system needs to output a file in a certain format for a government agency, then that agency might be considered an actor as well.

62.
An SME (Subject Matter Expert) is a person who has intimate knowledge about the work or process for which you are developing a system. They don't need to have any computer experience.

63.
An Essential Use Case is a nontechnical view of how your system will work with its users.

64.
A System Use Case defines the technical view of how your system will work.

65.
Business Rules are the rules and laws that govern how a business operates. An SME is typically the most accurate source of business rules.

66.
User Interface Diagrams are prototypes or designs for a programs user interface. It may contain forms and controls, as well as menu items.

67.
User Interface-Flow diagrams let you define the flow of the program in terms of the user interface, such as the steps a user must take to perform some process.

68.
A Change case represents possible or definite changes to a system. The goal of the change case is to design a flexible system and anticipate possible or definite changes so that the system can be designed to be easily adaptable.

69.
An interface represents a set of standard methods to provide some behavior or feature to a class. For a class to have some certain behavior, it declares that it will implement the interface that defines the behavior.

70.
Client—Entity for which the work is being done.
Project—The definition of the project and the group for the remaining items. Clients can have multiple projects.
Work Request—Identifies a request, feature, change, or bug report. Projects are made up of requests and features initially, and then as time goes on features, changes, and bug reports are added.
Task—The work performed by the entity developing the project. Tasks are the work performed to complete a Work Request.

71.
Failure of a programmer to define an abstract method in a subclass, an attempt by the programmer to call the super class's abstract method, and an attempt to declare an instance of the abstract super class in the program.

72.
A framework is a set of classes or class library that has been designed to work well together and that follows a certain paradigm.

73.
Objects that are very reusable across different applications (like a string class or stream hierarchy), objects that are reusable within a particular set of programs (like a student class and hierarchy for academic institution programs), and objects that simply will never be reused again anywhere.

74.
Objects are thought of as nouns (person, place, or thing). Tasks are thought of as verbs because they describe action within an application.

75.
A hierarchy is morphed when a member function has many versions of a behavior requiring many overloaded functions.

76.
Multiple inheritance should be used whenever a child needs to inherit attributes and behaviors from parents that are not related to each other.

77.
Early binding is the binding of a method call to a method definition and is performed at compile time if all the information is available at compile time.

78.
Late binding is the binding of a method call to a method definition and is performed at run time. It implicitly makes use of base class pointers or references to derived objects, and methods must be virtual.

79.
No. Unlike flow charts, Sequence diagrams do not show flow control; they show sequence.

80.
It represents the pseudo-destructor for a class. If garbage is collected, the finalize method is called, but there is no guarantee when or even if this will occur.

81.
Nonstatic data members occur in each instance of the class and nonstatic methods can work with them as well as static methods. Static data members occur only once no matter how many instances of a class and static methods can only work directly with static data members. You do not need to declare an instance of a class to use its static methods or properties.

82.
public class Derived extends Base { ...

83.
class Derived : public Base { ... // public may also be private or protected.

84.
class Derived : Base { ...

85.
It means that no class can be derived from it.

86.
It is compiled into bytecode, and then the Java Virtual Machine interprets the byte code.

87.
It is compiled into native machine code.

88.
It is compiled into byte code, and then the CLR recompiles it into native machine code.

89.
C++

90.
Java, since its bytecode can be used without recompiling. C# and the CLR are designed for this ability, but only currently available on Windows Desktop and Windows Mobile operating systems.

91.
Garbage collection releases the programming from the task of manually releasing memory. The disadvantage is that garbage collection systems are unpredictable as to when they release memory and may require manual coding to do so.

92.
C++, which supports pointers directly to memory. C# includes some support for memory access and Java provides none.

93.
Java and C#. C++ can mimic this behavior by defining an abstract class and using multiple inheritance.

94.
C++ and Java version 1.5

95.
J2EE—Java Enterprise Edition for servers, J2SE—Java Standard Edition for desktops, and J2ME—Java Micro Edition for handheld devices.

96.
The JVM, or Java Virtual Machine, is the program that must be installed on a computer in order to interpret and execute the compiled byte code of a Java program.

97.
The CLR, or Common Language Runtime, is the program that must be installed on a computer in order to interpret and compile the bytecode generated by compiling a C# program.

98.
C++, because it doesn't require a JVM or CLR to be in memory while it runs.

99.
ENIAC, built in the mid-1940s

100.
Grace Hopper coined the term when she found a moth stuck between some tubes, which was causing her program to act incorrectly.

Thursday, September 11, 2008

c++ program-Queue operation at front end using linked lists

#include < iostream>
#include < stdio.h>

using namespace std;

class node
{
public: int data;
node *ptr;
};

class linkedList
{
private: node *head;

public: linkedList() //constructor
{
head = NULL;
}

void insert_front();
int delete_front();
void display();

~linkedList() //destructor
{
delete head;
}
};// end of LL

void linkedList::insert_front()
{
node *newNode;
int item;
newNode= new node;
cout<< "enter the item to be inserted" < cin>> item;
newNode->data=item;
newNode->ptr=head;
head=newNode;
}

int linkedList::delete_front(void)
{
node *temp;
int item;
if(head==NULL)
{
cout<< "list is empty"<< endl;
return 1;
}

temp = head;
cout<< "deleted item is"<< temp->data<< endl;
item=temp->data;
head=temp->ptr;
delete(temp);
return item;
}

void linkedList::display()
{
node *temp;
temp=head;
cout<< " \n enter contents of list"<< endl;

while(temp!=NULL)
{
cout<< temp->data<< "->";
temp=temp->ptr;

}
cout<< "NULL"<< endl;
}

void main()
{
linkedList ll;
int choice, rpt;

while(rpt)
{
cout<< "1. Insert at front"<< endl;
cout<< "2. Delete from front"<< endl;
cout<< "3. Display"<< endl;
cout<< "4. exit"<< endl;

cout<< "enter the choice";

cin>> choice;

switch(choice)
{
case 1: ll.insert_front();
break;
case 2: ll.delete_front();
break;
case 3: ll.display();
break;
case 4: return;
}
cout<< "do you want to continue: yes: 1 or No: 0"<< endl;
cin>> rpt;
}
}

C++ program to write a function power() to raise a number m to a power n and taking default n value as 2

#include < iostream.h>
#include < stdlib.h>

float power(double m,int n=2)

{

int i;

double result=1;

for(i=0;i< n;i++)

result*=m;

return result;

}

void main()

{

double num,res;

int powr;

cout<< " enter the number\n";

cin>>num;

cout<< " enter the power\n";

cin>>powr;

res=power(num,powr);

cout<< " the result is ----> "<< res;

}

c++ program to reverse a sentence

#include < iostream.h >
#include < stdio.h >
#define MAX 100
#include < string.h>



void swap(char* , char*);

void str_rev(char *str)
{

char *fir = str;
char *end = str + (strlen(str) - 1);
swap(fir,end);

char *x = str;
char *y = x;

while (*x != '\0')
{
if(*x == ' ')
{
swap(y,x-1);
x=x+1;
y=x;
}

else
{
x++;
}

}
swap(y,x-1);

}

void swap(char *fir, char *end)
{
char temp;

while(fir < end)
{
temp = *fir;
*fir = *end;
*end = temp;
fir++;
end--;
}
}




void main()
{
printf( " enter text \n");
char text[MAX];
gets(text);
str_rev(text);
printf( " %s", text);
}

c++ program to reverse a sentence

#include < iostream.h >
#include < stdio.h >
#define MAX 100
#include < string.h>

void swap(char* , char*);

void str_rev(char *str)
{

char *fir = str;
char *end = str + (strlen(str) - 1);
swap(fir,end);

char *x = str;
char *y = x;

while (*x != '\0')
{
if(*x == ' ')
{
swap(y,x-1);
x=x+1;
y=x;
}

else
{
x++;
}

}
swap(y,x-1);

}

void swap(char *fir, char *end)
{
char temp;

while(fir < end)
{
temp = *fir;
*fir = *end;
*end = temp;
fir++;
end--;
}
}


void main()
{
printf( " enter text \n");
char text[MAX];
gets(text);
str_rev(text);
printf( " %s", text);
}

c++ program example of inheritance and virtual function

#include < stdio.h>
#include < iostream.h>
#include < stdlib.h>


// Prototype graphics library function to draw a circle

void glib_draw_circle (int x, int y, int radius);



// Shape base class declaration

class Shape

{

protected:

int m_x; // X coordinate

int m_y; // Y coordinate



public:

// Pure virtual function for drawing

virtual void Draw() = 0;



// A regular virtual function

virtual void MoveTo(int newX, int newY);



// Regular method, not overridable.

void Erase();



// Constructor for Shape

Shape(int x, int y);



// Virtual destructor for Shape

virtual ~Shape();

};



// Circle class declaration

class Circle : public Shape

{

private:

int m_radius; // Radius of the circle



public:

// Override to draw a circle

virtual void Draw();



// Constructor for Circle

Circle(int x, int y, int radius);



// Destructor for Circle

virtual ~Circle();

};



// Shape constructor implementation

Shape::Shape(int x, int y)

{

m_x = x;

m_y = y;

}



// Shape destructor implementation

Shape::~Shape()

{

//...

}



// Circle constructor implementation

Circle::Circle(int x, int y, int radius) : Shape (x, y)

{

m_radius = radius;

}



// Circle destructor implementation

Circle::~Circle()

{

//...

}



// Circle override of the pure virtual Draw method.

void Circle::Draw()

{

glib_draw_circle(m_x, m_y, m_radius);

}



void main()

{

// Define a circle with a center at (50,100) and a radius of 25

Shape *pShape = new Circle(50, 100, 25);



// Define a circle with a center at (5,5) and a radius of 2

Circle aCircle(5,5, 2);



// Various operations on a Circle via a Shape pointer

pShape->Draw();

pShape->MoveTo(100, 100);

pShape->Erase();

delete pShape;



// Invoking the Draw method directly

aCircle.Draw();

}

C++ program to Reverse a LINK LIST

#include < iostream>
#include < stdio.h>

using namespace std;

class node
{
public: int data;
node *ptr;
};

class linkedList
{
private: node *head;

public: linkedList() //constructor
{
head = NULL;
}

void insert_front();
void reverse();
void display();

~linkedList() //destructor
{
delete head;
}
};// end of LL

void linkedList::insert_front()
{
node *newNode;
int item;
newNode = new node;
cout<< " enter the item to be inserted" << endl;
cin >> item;
newNode->data=item;
newNode->ptr=head;
head=newNode;
}

void linkedList::reverse()
{
node *current, *temp;
current=NULL;

if(head==NULL)
{
cout<< "list is empty"<< endl;
}

while(head!=NULL)
{
temp=head;
head=head->ptr;
temp->ptr=current;
current=temp;
}
head=temp;

}


void linkedList::display()
{
node *temp;
temp=head;
cout<< "\ncontents of list"<< endl;

while(temp!=NULL)
{
cout<< temp->data<< "->";
temp=temp->ptr;

}
cout<< "NULL"<< endl;
}



void main()
{
linkedList ll;
int opt;

while(opt!=0)
{

ll.insert_front();

ll.display();


cout<< "do you want to continue: yes: 1 or No: 0"<< endl;
cin>>opt;
}

ll.reverse();

cout<< "after reversal ";
ll.display();

c++ program to find the number of times that a given word(i.e. a short string) occurs in a sentence (i.e. a long string!).

#include < stdio.h>
#include < conio.h>
#include < string.h>

void main()
{
char s1[20],s2[20];
int flag=0;

printf(" enter the first string");
gets(s1);
printf(" enter the second string");
gets(s2);
char *ptr1=s1;
char *ptr2=s2;
int count=0,flag1=0;
int m= strlen(s2);
while(1)
{
while(1)
{

char ch=*ptr1;
if(ch==' ')
break;
if(ch==NULL)
{
flag1=1;
break;
}
if(*ptr1==*ptr2)
{

*ptr1++;
*ptr2++;
count++;

}
else
{
count--;
*ptr1++;
}
}

if(flag1!=1)
{
if(*ptr1==' ')
ptr1++;
if(count==m)
{
flag++;
}
ptr2=s2;
count=0;
}
else
{
if(count==m)
{
flag++;
}
break;

}
}
if(flag!=0)
{
printf(" the no of word occurence is %d",flag);
}
else
{
printf(" word absent");
}
}

Tuesday, September 9, 2008

HTML Code to generate browser details

< html >
< body >

< script type="text/javascript">
var x = navigator
document.write("CodeName=" + x.appCodeName)
document.write("< br / >")
document.write("MinorVersion=" + x.appMinorVersion)
document.write("< br / >")
document.write("Name=" + x.appName)
document.write("< br / >")
document.write("Version=" + x.appVersion)
document.write("< br / >")
document.write("CookieEnabled=
" + x.cookieEnabled)
document.write("< br / >")
document.write("CPUClass=" + x.cpuClass)
document.write("< br / >")
document.write("OnLine=" + x.onLine)
document.write("< br / >")
document.write("Platform=" + x.platform)
document.write("< br / >")
document.write("UA=" + x.userAgent)
document.write("< br / >")
document.write("BrowserLanguage=" + x.browserLanguage)
document.write("< br / >")
document.write("SystemLanguage=" + x.systemLanguage)
document.write("< br / >")
document.write(" UserLanguage = " + x.userLanguage)
< /script >

< /body >
< /html >

Friday, September 5, 2008

C code snippet to display array implementation of stack

#include < stdio.h>
#include < conio.h>
#include < process.h>

#define STACK_SIZE 10

void push(int item,int *top,int s[])
{
if(*top==STACK_SIZE-1)
{
printf(" Stack overflow\n");
return;
}

s[++(*top)]=item;
}

int pop(int *top,int s[])
{
int item_deleted;

if(*top==-1)
{
return 0;
}

item_deleted=s[(*top)--];

return item_deleted;
}



void display(int top,int s[])
{
printf(" contents of stack are\n");

for(int i=0;i<= top;i++)
{
printf("%d ",s[i]);
}
}


void main()
{
int top,s[20],choice,item,item_deleted;

top=-1;

for(;;)
{
printf(" 1.Push\n2.Pop\n3.display\n");
printf(" 4.Exit\n");
printf(" Enter choice\n");
scanf(" %d",&choice);

switch(choice)
{
case 1:
printf(" Enter item to be inserted\n");
scanf(" %d",&item);
push(item,&top,s);
break;
case 2:
item_deleted=pop(&top,s);
printf(" The item deleted=%d",item_deleted);
break;
case 3:
display(top,s);
break;
default:
exit(0);
}
}
}

C program to show all operations on singly linked list

#include < stdio.h>
#include < process.h>
#include < malloc.h>


struct node
{
int info;
struct node *link;
};

typedef struct node *NODE;


NODE getnode()
{
NODE x;

x=(NODE) malloc( sizeof(struct node));

if(x==NULL)
{
printf(" Out of memory\n");
exit(0);
}

return x;
}

void freenode( NODE x)
{
free(x);
}



NODE insert_front(int item,NODE first)
{
NODE temp;

temp=getnode();

temp->info=item;
temp->link=first;

return temp;
}

NODE insert_rear(int item,NODE first)
{
NODE temp;
NODE cur;

temp=getnode();

temp->info=item;
temp->link=NULL;

if(first==NULL)
return temp;

cur=first;

while(cur->link!=NULL)
{
cur=cur->link;
}

cur->link=temp;

return first;
}

NODE delete_front(NODE first)
{
NODE temp;
if(first== NULL)
{
printf(" list empty");
return first;
}

temp=first;
first=first->link;

printf(" Item deleted=%d\n",temp->info);
freenode(temp);

return first;
}

NODE delete_rear(NODE first)
{
if(first==NULL)
{
printf(" list empty\n");
return first;
}

if(first->link==NULL)
{
printf(" Item deleted=%d\n",first->info);
freenode(first);
first=NULL;
return first;
}
NODE prev=NULL;
NODE cur=first;

while(cur->link!=NULL)
{
prev=cur;
cur=cur->link;
}

printf(" Item deleted=%d\n",cur->info);
freenode(cur);

prev->link=NULL;

return first;
}

void display(NODE first)
{
if(first==NULL)
{
printf(" list empty\n");
return;
}

printf(" The contents of list\n");

NODE temp=first;

while(temp!=NULL)
{
printf("%d ",temp->info);
temp=temp->link;
}

}


void main()
{
NODE first=NULL;
int choice,item,item_deleted;

for(;;)
{
printf(" 1.insert front\n2insert rear\n3delete front\n4.delete rear\n5.display");
printf(" 6.exit\n");

printf(" enter the choice\n");
scanf(" %d",&choice);

switch(choice)
{
case 1:
printf(" Enter the item to be inserted\n");
scanf(" %d",&item);
first=insert_front(item,first);
break;

case 2:
printf(" Enter the item to be inserted\n");
scanf(" %d",&item);
first=insert_rear(item,first);
break;

case 3:
delete_front(first);
break;

case 4:
delete_rear(first);
break;

case 5:
display(first);
break;

default:
exit(0);

}
}
}

C code to demonstrate operations on stack

#include
#include
#include


struct node
{
int info;
struct node *link;
};
typedef struct node *NODE;

NODE getnode()
{
NODE x;

x=(NODE) malloc( sizeof( struct node));

if(x==NULL)
{
printf(" Out of memory\n");
exit(0);
}

return x;
}

void freenode(NODE x)
{
free(x);
}






NODE insert_front(int item,NODE first)
{
NODE temp;

temp=getnode();

temp->info=item;
temp->link=first;

return temp;
}

NODE delete_front(NODE first)
{
NODE temp;
if(first==NULL)
{
printf(" list empty");
return first;
}

temp=first;
first=first->link;

printf(" Item deleted=%d\n",temp->info);
freenode(temp);

return first;
}



void display(NODE first)
{
if(first==NULL)
{
printf(" list empty\n");
return;
}

printf(" The contents of list\n");

NODE temp=first;

while(temp!=NULL)
{
printf("%d ",temp->info);
temp=temp->link;
}

}



void main()
{
NODE first=NULL;
int choice,item;

for(;;)
{
printf(" 1.insert front\n2.delete front\n3.display\n4.exit\n");
printf(" Enter choice\n");
scanf(" %d",&choice);

switch(choice)
{
case 1:
printf(" Item:");
scanf(" %d",&item);
first=insert_front(item,first);
break;
case 2:
first=delete_front(first);
break;
case 3:
display(first);
break;
default:
exit(0);
}
}
}

C program to demostrate Queue using singly linked list

#include < stdio.h >
#include < malloc.h >
#include < process.h >


struct node
{
int info;
struct node *link;
};
typedef struct node *NODE;

NODE getnode()
{
NODE x;

x=(NODE) malloc(sizeof(struct node));

if(x== NULL)
{
printf(" Out of memory\n");
exit(0);
}

return x;
}

void freenode(NODE x)
{
free(x);
}


NODE insert_rear(int item,NODE first)
{
NODE temp;
NODE cur;

temp=getnode();

temp->info=item;
temp->link=NULL;

if(first== NULL)
return temp;

cur=first;

while(cur->link!=NULL)
{
cur=cur->link;
}

cur->link=temp;

return first;
}



NODE delete_front(NODE first)
{
NODE temp;
if(first==NULL)
{
printf("list empty");
return first;
}

temp=first;
first=first->link;

printf(" Item deleted=%d\n",temp->info);
freenode(temp);

return first;
}





void display(NODE first)
{
if(first==NULL)
{
printf(" list empty\n");
return;
}

printf(" The contents of list\n");

NODE temp=first;

while(temp!= NULL)
{
printf(" %d ",temp->info);
temp=temp->link;
}

}



void main()
{
NODE first= NULL;
int choice,item;

for(;;)
{
printf(" 1.insert rear\n2.delete front\n3.display\n4.exit\n");
printf(" Enter choice\n");
scanf(" %d", &choice);

switch(choice)
{
case 1:
printf("Item:");
scanf("%d",&item);
first=insert_rear(item,first);
break;
case 2:
first=delete_front(first);
break;
case 3:
display(first);
break;
default:
exit(0);
}
}
}

C# program to Demonstrate the difference between prefix

using System;

class PrePostDemo {
public static void Main() {
int x, y;
int i;

x = 1;
Console.WriteLine("Series generated using y = x + x++;");
for(i = 0; i < 10; i++) {

y = x + x++; // postfix ++

Console.WriteLine(y + " ");
}
Console.WriteLine();
x = 1;
Console.WriteLine("Series generated using y = x + ++x;");
for(i = 0; i < 10; i++) {

y = x + ++x; // prefix ++

Console.WriteLine(y + " ");
}
Console.WriteLine();

}
}

C# program: Use bitwise OR to make a number odd using bitwise '|'.

using System;

class MakeOdd {
public static void Main() {
ushort num;
ushort i;

for(i = 1; i <= 10; i++) {
num = i;

Console.WriteLine("num: " + num);

num = (ushort) (num | 1); // num | 0000 0001

Console.WriteLine("num after turning on bit zero: "
+ num + "\n");
}
}
}

C# program to convert from long to double

using System;

class LtoD {
public static void Main() {
long L;
double D;

L = 100123285L; // D=100123285L ;L=D illegal
D = L;

Console.WriteLine("L and D: " + L + " " + D);
}
}

C# program to demonstrate jagged arrays.

using System;

class Jagged {
public static void Main() {
int[][] jagged = new int[3][];
jagged[0] = new int[4];
jagged[1] = new int[3];
jagged[2] = new int[5];

int i;

// store values in first array
for(i=0; i < 4; i++)
jagged[0][i] = i;

// store values in second array
for(i=0; i < 3; i++)
jagged[1][i] = i;

// store values in third array
for(i=0; i < 5; i++)
jagged[2][i] = i;

// display values in first array
for(i=0; i < jagged[0].Length; i++)
Console.Write(jagged[0][i] + " ");

Console.WriteLine();

// display values in second array
for(i=0; i < jagged[1].Length; i++)
Console.Write(jagged[1][i] + " ");

Console.WriteLine();

// display values in third array
for(i=0; i < jagged[2].Length; i++)
Console.Write(jagged[2][i] + " ");

Console.WriteLine();

}
}

C# Program-Use bitwise AND to determine if a number is odd.

using System;

class IsOdd {
public static void Main() {
ushort num;

num = 10;

if((num &1)==1)
Console.WriteLine(" This won't display.");

num = 11;

if((num & 1) == 1)
Console.WriteLine( num + " is odd.");

}
}

C# code snippet to demonstrate an array over-run.

using System;

class ArrayErr {
public static void Main() {
int[] sample = new int[10];
int i;

// generate an array overrun
for(i = 0; i < 100; i = i+1)
sample[i] = i;
}
}

C# program to demonstrate 2-D array

using System;

class TwoD {
public static void Main() {
int t, i;
int[,] table = new int[3, 4];

for(t=0; t < 3; ++t) {
for(i=0; i < 4; ++i) {
table[t,i] = (t*4)+i+1;
Console.Write( table[t,i] + " ");
}
Console.WriteLine();
}
}
}

C# program to display the bits within a byte!

/* C# code snippet to display the bits within a byte using bitwise '&' */

using System;

class ShowBits {
public static void Main() {
int t;
byte val;
val = 123;
for(t=128; t > 0; t = t/2) {
if((val & t) != 0) Console.Write(" 1 ");
if((val & t) == 0) Console.Write(" 0 ");
}
}
}

A sample C# code snippet

class variabledemo {
//main method
public static void Main()
{
int first=5;
int second;
Console.WriteLine(" first value: {0}",first);
second=10;
Console.WriteLine(" first value: {0}",second);
}
}

Thursday, September 4, 2008

C program to count no. of characters and words

/* assuming that word separators are , . ' '(space) considering that , . ' '(space) are not characters */

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

void main()
{
int flag=0;
char c;
int no_words=0,no_char=0;

printf("Enter sentence...\n");

while((c=getchar())!='\n')
{
no_char++;
if(c==' '||c=='.'||c==',')
{
if(flag==1)
{
}
else
{

no_words++;

flag=1;
}
no_char--;;
}
else
{
flag=0;
}
}
printf("Number of words are %d",no_words+1);
printf("Number of characters are %d",no_char);
getch();
}

C pseudo code to reverse an integer array

/* a is the integer array and n is the size of the array */

void revIntArray(int a[], int n)
{
int i;
for(i=0;i< n/2;i++){
intSwap( &a[i], &a[n-i-1]);
}
}

//intSwap is the swap function to swap two integers

C Program to REVESE AN INTEGER

//C program used to reverse an integer,count the no. of digits and calculate sum

#include < stdio.h>
#include < string.h>
#include < conio.h>
void main()
{
static char num[1000];
int sum=0;
int i=0,n=0;
printf("Enter the number:");
gets(num);// a=gets();
n=strlen(num);
printf("No of Digits=%d",n);

for(i= n-1;i> =0;i--)
{
printf("%c",num[i]);
}
printf("sum of digits:");
for(i=0;i< n;i++)
sum+= num[i];
printf("%d", sum);

getch();
}

Wednesday, September 3, 2008

C program to find column sum of matrix

#include < iostream.h >
#include < conio.h >
void sum(int a[][20],int row, int col)
{
int colsum[10],i,j;
for(i=0;i< col;i++){
colsum[i]=0;
for(j=0;j< row;j++){
colsum[i]=a[j][i]+colsum[i] ;
}}
cout<< "\nTHE SUM OF THE COLOUMN" << endl;
for(i=0;i< row;i++){
cout << "SUM OF THE ELEMENTS OF THE COLOUMN "<< i+1<< "="<< colsum[i]<< endl;
}
}
void main(){
clrscr();
int colsum[10],i,j,row,col,a[20][20];
cout<< "ENTER THE NUMBERS OF ROWS AND COLOUMN"<cin>> row>> col;
cout<< "ENTER THE ELEMENTS INTO THE MATRIX"<< endl;
for(i=0;i< row;i++){
for(j=0;j< col;j++){
cin>> a[i][j];
}}
cout<< "THE MATRIX IS"<< endl;
for(i=0;i< row;i++){
cout<< endl;
for(j=0;j< col;j++){
cout<< a [i][j]<< "\t";
}}
sum(a,row,col);
getch();
}

C++ program for implementation of the stack using singly linked list.

Stack is a list of elements in which insertions and deletions are at the same end of the list called top.

The other end is known as Bottom.Insertion is also known as push,deletion is also known as pop.

The operations performed on a stack are

1)push(): This is the function which is for insertion(pushing)of an element into stack. It is similar to the insertion of an element at the end of a single linked list. See the function insert_end() in the program for operations of single linked list

2)pop(): This is the function which is for deletion(popping up) of an element from the stack. It is similar to the deletion of an element at the end of a single linked list. see the function delete_end() in the program for operations of single linked list

3)stack_display():This is the function which is for displaying the elements of a stack. It is similar to the forward traversal of a single linked list. See the function ftraverse() in the program for operations of single linked list

#include < iostream.h >

#include < stdlib.h >

class stack

{

int element;

stack* next;

public:

stack* push(stack*,int);

stack* pop(stack*);

void stack_display(stack*);

}*head,object;

stack* stack::push(stack* head,int key)

{

stack* temp,*temp1;

temp1=head;

temp=new stack;

temp->element=key;

temp->next=NULL;

if(head==NULL)

head=temp;

else

{

while(head->next!=NULL)

head=head->next;

head->next=temp;

head=temp1;

}

return head;

}

stack* stack::pop(stack* head)

{

stack* temp;

if(head!=NULL)

{

temp=head;

if(head->next==NULL)

{

cout<< ”\nthe pooped element from the stack is: “<< head->element<< endl;

return NULL;

}

while(head->next->next!=NULL)

head=head->next;

cout<< ”the popped element from the stack is “<< head->next->element;

cout<
head->next=head->next->next;

head=temp;

return head;

}

else

{

cout<< ”\nit is impossible to pop an element from the stack as “;

return head;

}

}

void stack::stack_display(stack* head)

{

if(head!=NULL)

{

while(head->next!=NULL)

{

cout<< head->element<<”->”;

head=head->next;

}

cout<< head->element;

cout<< endl;

}

else

cout<< ”the stack is empty\n”;

}

void choice()

{

int key,ch;

cout<< ”\nchoose the operation to be performed\n”;

cout<< ”\n1.push\t2.pop\t3.exit\n\n”;

cin>>ch;

head=NULL;

while(1)

{

switch(ch)

{

case 1:



cout<< ”——————————————————————————–\n”;

cout<< ”\nenter the element to be pushed\n”;

cin>>key;

head=object.push(head,key);

cout<< ”\nthe stack after push operation is \n”;

object.stack_display(head);



cout<<”——————————————————————————–\n”;

break; case 2:

cout<< ”\n“““““““““““““““““““““““““““““““““““““““\n”;

head=object.pop(head);

cout<< ”\nthe stack after pop operation is :\n”;

object.stack_display(head);



cout<< ”\n“““““““““““““““““““““““““““““““““““““““\n”;

break;

case 3:

exit(1);

default:

cout<< ”\nenter the correct choice\n”;

break;

}

cout<< ”\nchoose the operation to be performed\n”;

cout<< ”\n1.push\t2.pop\t3.exit\n”;

cin>>ch;

}

}

void main()

{

choice();

}

Tuesday, September 2, 2008

Generate Fibonacci Series

/*Pseudo code to generate Fibonacci Series using different types of Recursion Techniques */

Using Binary Recursion: Binary Recursion is a process where function is called twice at a time inplace of once at a time. Mostly it's using in data structure like operations for tree as traversal, finding height, merging, etc... Let see how Fibonacci series is generated!

Run Time Version Code:

int FibNum(int n)
{
// Base conditions
if (n < 1)
return -1;
if (1 == n || 2 == n)
return 1;

// Recursive call by Binary Method
return FibNum(n - 1) + FibNum(n - 2);


Compile Time Version Code

// Base Conditions
template<>
struct FibNum<2>
{
enum { val = 1 };
};
template <>
struct FibNum<1>
{
enum { val = 1 };
};

// Recursive call by Binary Method
template
struct FibNum
{
enum { val= FibNum::val + FibNum::val };
};

Tail Recursion:
In this method, recursive function is called at the last. So it's more efficient than linear recursion method. Means you can say termination point will come(100%) only you have to put that condition.

Run Time Version Code:

int FibNum(int n, int x, int y)
{
if (1 == n) // Base Condition
{
return y;
}
else // Recursive call by Tail method
{
return FibNum(n-1, y, x+y);
}
}

Compile Time Version Code

template
struct FibNum
{
// Recursive call By tail method
enum
{
val = FibNum::val
};
};

// Base Condition or Termination
template
struct FibNum<1, x, y>
{
enum { val= FibNum::val + FibNum::val };
};

Matrix multiplication

/* C program to multiply two matrices */

Monday, September 1, 2008

Binary search

#include"stdio.h"
#include"conio.h"

void bsearch(int a[],int n,int item)
{
int beg=0,last=n-1,mid;
while(beg<=last){
mid=(beg+last)/2;
if(a[mid]==item){
printf("the element is present in the index %d",mid);
break; }
else if(a[mid]>last)
last=mid-1;
else
beg=mid+1;
}
if(beg>last)
printf("element is not present");
}
void main(){
clrscr();
int a[20],n,item,i;
printf("enter the no of elements you want to enter");
scanf("%d",&n);
printf("enter the elements");
for(i=0;i< n;i++){
scanf("%d",&a[i]);
}
printf("enter the element you want to search");
scanf("%d",&item);
bsearch(a,n,item);
}

Bubble sort

#include"stdio.h"
#include"conio.h"
void bubble(int a[],int n){
int temp,itv=0,i,j,k;
for(i=0;i< n;i++){
for(j=0;j< (n-1)-i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}}
printf("after iteration %d \n",++itv);
for(k=0;k< n;k++){
printf("%d ",a[k]);
}
}
}
void main()
{
int a[20],i,n;
printf("enter the no of elements you want to enter");
scanf("%d",&n);
cout<<"enter the elements";
for(i=0;i< n;i++){
scanf("%d",&a[i]);
}
bubble(a,n);
}

Selection sort

//PROGRAM FOR SELECTION SORT
#include"stdio.h"
#include"conio.h"
void ssort(int a[],int n)
{
int i,j,pos,small,temp;
for(i=0;i< n;i++)
{
small=a[i];
for(j=i+1;j< n;j++)
{
if(small>a[j])
{
small=a[j];
pos=j;
}
}
if(small!=a[i])
{
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
}
printf("AFTER ITERATION %d : \n",i+1);
for(j=0;j< n;j++)
{
printf("%d ",a[j]);
}
}
}
void main()
{
int a[20],i,n;
clrscr();
printf("ENTER HOW MANY ELEMENTS YOU WANT TO ENTER");
scanf("%d",&n);
for(i=0;i< n;i++)
scanf("%d",&a[i]);
ssort(a,n);
getch();
}

Palindrome

#include"conio.h"
#include"string.h"
#include"stdio.h"
void main()
{
clrscr();
char a[20];
int i=0,j,flag;
printf("\n Enter the string\n");
gets(a);
j=strlen(a)-1;
while(i<=j) {
if(a[i]==a[j])
flag=0;
else{
flag=-1;
printf("string is not a palindrome");
break;
}
i++;
j--;
}
if(flag==0){
printf("string is a palindrome");
}
getch();
}

Lower Matrix

#include"stdio.h"
#include"conio.h"
void disp(int n)
{
int k,l,i,j,a[20][20];
k=0;
for(i=0;i< n;i++)
{ l=0;
k=k+1;
for(j=0;j< n;j++)
{ if(l< k)
{l=l+1;
a[i][j]=l;
}
else
a[i][j]=0;
}
}
printf("\nMatrix is\n");
for(i=0;i< n;i++)
{ printf("\n");
for(j=0;j< n;j++)
printf("%d \t",a[i][j]);
}

}

void main()
{
int a[20][20],i,j,n;
clrscr();
printf("\n enter value of n\n");
scanf("%d",&n;
disp(n);
getch();
}

Linear Search

#include  
  
#define NMAX 10  
  
int getIntArray(int a[], int nmax, int sentinel);  
void printIntArray(int a[], int n);  
int linear(int a[], int n, int who);  
  
  
int main(void)
{  
  int x[NMAX];  
  int hmny;  
  int who;  
  int where;  
  
  
  hmny = getIntArray(x, NMAX, 0);  
  printf("The array was: \n");  
  printIntArray(x,hmny);  
  printf("Now we do linear searches on this data\n");  
  do{  
  printf("Enter integer to search for [0 to terminate] : ");  
  scanf("%d", &who);  
  if(who==0)break;  
  where = linear(x,hmny,who);  
  if (where<0)
{  
  printf("Sorry, %d is not in the array\n",who);  
  }
else  
  printf("%d is at position %d\n",who,where);  
  }while(1);  
}  
  
< script type="text/javascript">
< /script>
< script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
< /script>
  
void printIntArray(int a[], int n)  
  /* n is the number of elements in the array a.  
  * These values are printed out, five per line. */  
{  
  int i;  
  
  
  for (i=0; i< n; )
{  
  printf("\t%d ", a[i++]);  
  if (i%5==0)  
  printf("\n");  
  }  
  printf("\n");  
}  
  
  
int getIntArray(int a[], int nmax, int sentinel)  
  /* It reads up to nmax integers and stores then in a; sentinel  
  * terminates input. */  
{  
  int n = 0;  
  int temp;  
  
  
  do {  
  printf("Enter integer [%d to terminate] : ", sentinel);  
  scanf("%d", &temp);  
  if (temp==sentinel) break;  
  if (n==nmax)  
  printf("array is full\n");  
  else  
  a[n++] = temp;  
  }while (1);  
  return n;  
}  
  
  
int linear(int a[], int n, int who)  
  /* Given the array a with n elements, searches for who.  
  * It returns its position if found, otherwise it returns  
  * -1.  
  */  
{  
  int lcv;  
  for (lcv=0;lcv< n;lcv++)  
  if(who == a[lcv])return lcv;  
  return (-1);  
}  

Reverse a Linked-listed

void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;

for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}

curnext->next = cur;
}
}


Print Pyramid

/* Program to print pyramid when no. of lines specified by the user*/

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

printf("enter the no. of required lines");
scanf("%d",&n);
printf"(the pyramid is \n");
for(i=0;i<=n;i++)
{
for(j=n;j>=i;j--)
printf(" \t");
for(j=1;j<=i;j++)
printf("%d \t",j);
for(k=i-1;k>=1;k--)
printf("%d \t",k);
printf("\n");
}
getch();
}