Code Crackerzz
Here we will discussing many codes either a complex one or an easy so that one can enrich their knowledge. 1. We will discuss a single program daily.
3.
Here we will discussing many codes either a complex one or an easy so that one can enrich their knowledge.
2. I will Update that single program and if there is any other possibility to simplify the code in much easier manner, then please post it.
4. People who want the code of some programs can also update the post so that we all will try to crack that code and help that person in need. These are my basic plans. Suggestion are always welcome.
24/01/2017
http://vanillajava.blogspot.in/2011/08/strange-hello-world-in-java.html
Strange Hello World in Java Overview This is a strange Hello World program because it only needs to be compiled, not run. How does it work? Hint: it only works on MS-DO...
PROGRAM FOR PLAYING THE GAME: TIC TAC TOE. Run It and Enjoy
import java.util.*;
class TicTacToe {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String P1, P2;
int i, j, c = '0', n = 1, ch;
boolean flag1, flag2, flag3 = false;
System.out.println("Type name of player 1");
P1 = sc.nextLine();
System.out.println("Type name of player 2");
P2 = sc.nextLine();
System.out.println("\n" + P1 + " will enter 'X'\n" + P2 + " will enter 'O'");
char Ar1[][] = { { '1', '2', '3' }, { '4', '5', '6' }, { '7', '8', '9' } };
char Ar2[][] = { { ' ', ' ', ' ' }, { ' ', ' ', ' ' }, { ' ', ' ', ' ' } };
System.out.println("\nGeneral Form (1,2,3,... indicate the place number):");
System.out.println("+---+---+---+");
System.out.println("| " + Ar1[0][0] + " | " + Ar1[0][1] + " | " + Ar1[0][2] + " |");
System.out.println("+---+---+---+");
System.out.println("| " + Ar1[1][0] + " | " + Ar1[1][1] + " | " + Ar1[1][2] + " |");
System.out.println("+---+---+---+");
System.out.println("| " + Ar1[2][0] + " | " + Ar1[2][1] + " | " + Ar1[2][2] + " |");
System.out.println("+---+---+---+");
while (n 9) {
System.out.println("Out of range, try again");
flag1 = false;
} else {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
if ((int) Ar1[i][j] == (ch + 48)) {
flag2 = true;
if (n % 2 == 1) {
Ar2[i][j] = 'X';
Ar1[i][j] = Ar2[i][j];
} else {
Ar2[i][j] = 'O';
Ar1[i][j] = Ar2[i][j];
}
break;
}
}
}
if (flag2 == false)
System.out.println("Place already filled, try again");
}
} while (flag1 == false || flag2 == false);
System.out.println("+---+---+---+");
System.out.println("| " + Ar2[0][0] + " | " + Ar2[0][1] + " | " + Ar2[0][2] + " |");
System.out.println("+---+---+---+");
System.out.println("| " + Ar2[1][0] + " | " + Ar2[1][1] + " | " + Ar2[1][2] + " |");
System.out.println("+---+---+---+");
System.out.println("| " + Ar2[2][0] + " | " + Ar2[2][1] + " | " + Ar2[2][2] + " |");
System.out.println("+---+---+---+");
if (n >= 5) {
if ((Ar1[0][0] == Ar1[1][1] && Ar1[1][1] == Ar1[2][2])
|| (Ar1[0][2] == Ar1[1][1] && Ar1[1][1] == Ar1[2][0])) {
if (Ar1[1][1] == 'X')
System.out.print("\nCongratulations " + P1 + ", you win it playing diagonally");
else if (Ar1[1][1] == 'O')
System.out.print("\nCongratulations " + P2 + ", you win it playing diagonally");
flag3 = true;
}
for (i = 0; i < 3; i++) {
if (Ar1[i][0] == Ar1[i][1] && Ar1[i][1] == Ar1[i][2]) {
if (flag3 == true)
System.out.println(" and also in row " + (i + 1));
else {
if (Ar1[i][0] == 'X')
System.out.print("\nCongratulations " + P1 + ", you win it playing in row " + (i + 1));
else if (Ar1[i][0] == 'O')
System.out.print("\nCongratulations " + P2 + ", you win it playing in row " + (i + 1));
}
flag3 = true;
}
if (Ar1[0][i] == Ar1[1][i] && Ar1[1][i] == Ar1[2][i]) {
if (flag3 == true)
System.out.println(" and also in column " + (i + 1));
else {
if (Ar1[0][i] == 'X')
System.out
.print("\nCongratulations " + P1 + ", you win it playing in column " + (i + 1));
else if (Ar1[0][i] == 'O')
System.out
.print("\nCongratulations " + P2 + ", you win it playing in column " + (i + 1));
}
flag3 = true;
}
}
}
if (flag3 == true)
break;
n++;
}
if (flag3 == false)
System.out.println("\nIt is a draw");
}
}
A tricky question asked in an interview.
How can you find the minimum of 4 numbers in java if the constraints were imposed like
1. Should not use inbuilt minimum function.
2. Should not use > , < operator.
What will be your answer?
Well, we are back.
Sorry for a big gap... :D
Hello People.
We will be back after few dayz with lot more tricky questions and solutions for that.
Hope for the best.
Have a good time. :D
at the sample program and predict the output
main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Program to check if strings are rotations of each other or not
# include
# include
# include
/* Function checks if passed strings (str1 and str2)
are rotations of each other */
int areRotations(char *str1, char *str2)
{
int size1 = strlen(str1);
int size2 = strlen(str2);
char *temp;
void *ptr;
/* Check if sizes of two strings are same */
if (size1 != size2)
return 0;
/* Create a temp string with value str1.str1 */
temp = (char *)malloc(sizeof(char)*(size1*2 + 1));
temp[0] = '\0';
strcat(temp, str1);
strcat(temp, str1);
/* Now check if str2 is a substring of temp */
ptr = strstr(temp, str2);
free(temp); // Free dynamically allocated memory
/* strstr returns NULL if the second string is NOT a
substring of first string */
if (ptr != NULL)
return 1;
else
return 0;
}
/* Main program to test areRotations */
int main()
{
char *str1 = "AACD";
char *str2 = "ACDA";
if (areRotations(str1, str2))
printf("Strings are rotations of each other");
else
printf("Strings are not rotations of each other");
getchar();
return 0;
}
#--Simple way to create your own header files in C/C++ -- #
1. Open notepad and write the function that you want to use in your program. An example is shown below.
int multiply(int a,int b)
{
return(a*b);
}
2. Now save the notepad file with .h extension.
Like in above example we are creating a function for multiply, so save this file with name sum.h in INCLUDE or BIN folder (you can use any other name).
3. After that write a program that uses this multiply function and include the header file that you have just created.
//header file created by you
void main()
{
int a,b,s;
clrscr();
printf("Enter the value of a and b:");
scanf("%d%d",&a,&b);
s=multiply(a,b);
printf("Multiply=%d",s);
getch();
}
Its too simple right
Real Fact :
First language
Ada Lovelace and Babbage and its nephew were writing programs for the project of "difference engine", and then the "analytical engine".
In 1945, the german K. Zuse, inventor of the Z3 computer would have defined an evolved language for this engine (with arrays and records).
Question3
# Program to Sort Words in Dictionary Order
int main(){
int i,j;
char str[10][50],temp[50];
printf("Enter 10 words:\n");
for(i=0;i
Question2
# Source Code to Find Largest Element Using Dynamic Memory Allocation #
int main(){
int i,n;
float *data;
printf("Enter total number of elements ");
scanf("%d",&n);
data=(float*)calloc(n,sizeof(float)); /* Allocates the memory for 'n' elements */
if(data==NULL)
{
printf("Memory not allocated.");
exit(0);
}
printf("\n");
for(i=0;i
Description
1. Here we will discussing many codes either a complex one or an easy so that one can enrich their knowledge.
2. We will discuss a single program daily.
3. I will Update that single program and if there is any other possibility to simplify the code in much easier manner, then please post it.
4. People who want the code of some programs can also update the post so that we all will try to crack that code and help that person in need.
These are my basic plans.
Suggestion are always welcome.
If you really like it and want to spread this page, please share it with your friends who can take an advantage from this.
Click here to claim your Sponsored Listing.
Category
Website
Address
Manipal
Manipala