Monday, November 3, 2014
Friday, October 31, 2014
To find wheather the girl you love will be girlfriend or not using C
4:07 PM
No comments
#include<stdio.h>
int main ( )
{
char rply;
printf("Propose the girl you love: \n");
printf("enter the answer ( y for yes and n for no):");
scanf("%c",& rply);
if(rply=='y')
printf("She is your girlfriend now");
if(rply=='n')
{
printf("She is not your girlfriend \n");
printf("Keep trying");
}
return 0;
}
int main ( )
{
char rply;
printf("Propose the girl you love: \n");
printf("enter the answer ( y for yes and n for no):");
scanf("%c",& rply);
if(rply=='y')
printf("She is your girlfriend now");
if(rply=='n')
{
printf("She is not your girlfriend \n");
printf("Keep trying");
}
return 0;
}
Wednesday, October 29, 2014
How to find the fibonacci series using C and java
7:47 AM
No comments
UAING C
#include<stdio.h>
int main()
{
int i, fibi1, fibi2, fibi3;
int k=5 ;
fibi1 = 0;
fibi2 = 1;
printf( "The Fibonacci numbers are: " );
printf( "%d \t %d \t", fibi1, fibi2 );
for(i=0; i<k-2 ;i++)
{
fibi3= fibi1 + fibi2;
fibi1=fibi2;
fibi2=fibi3;
printf("%d \t", fibi3);
}
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int fibonacci = 5;
int[] fibo = new int[fibonacci];
fibo[0] = 0;
fibo[1] = 1;
System.out.print("The Fibonacci numbers are: ");
System.out.print(" " + fibo[0] + " " + fibo[1]);
for(int i=2; i < fibonacci; i++)
{
fibo[i] = fibo[i-1] + fibo[i-2];
System.out.print(" " + fibo[i]);
}
}
}
..........................................................................................................
in both java and c the output will be
The Fibonacci numbers are: 0 1 1 2 3
...........................................................................................................
IF WE WANT THE USER TO INPUT THE NUMBERS:
USING C
#include<stdio.h>
int main()
{
int i, fibi1, fibi2, fibi3, k;
fibi1 = 0;
fibi2 = 1;
printf("enter the number of fibonacci numbers to generate: ");
scanf( "%d", &k );
printf( "The Fibonacci numbers are: " );
printf( "%d \t %d \t", fibi1, fibi2 );
for(i=0; i<k-2 ;i++)
{
fibi3= fibi1 + fibi2;
fibi1=fibi2;
fibi2=fibi3;
printf("%d \t", fibi3);
}
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int fibonacci;
System.out.print("enter the number of fibonacci numbers to generate:");
fibonacci= sc.nextInt();
int[] fibo = new int[fibonacci];
fibo[0] = 0;
fibo[1] = 1;
System.out.print("The Fibonacci numbers are: ");
System.out.print(" " + fibo[0] + " " + fibo[1]);
for(int i=2; i < fibonacci; i++)
{
fibo[i] = fibo[i-1] + fibo[i-2];
System.out.print(" " + fibo[i]);
}
}
}
#include<stdio.h>
int main()
{
int i, fibi1, fibi2, fibi3;
int k=5 ;
fibi1 = 0;
fibi2 = 1;
printf( "The Fibonacci numbers are: " );
printf( "%d \t %d \t", fibi1, fibi2 );
for(i=0; i<k-2 ;i++)
{
fibi3= fibi1 + fibi2;
fibi1=fibi2;
fibi2=fibi3;
printf("%d \t", fibi3);
}
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int fibonacci = 5;
int[] fibo = new int[fibonacci];
fibo[0] = 0;
fibo[1] = 1;
System.out.print("The Fibonacci numbers are: ");
System.out.print(" " + fibo[0] + " " + fibo[1]);
for(int i=2; i < fibonacci; i++)
{
fibo[i] = fibo[i-1] + fibo[i-2];
System.out.print(" " + fibo[i]);
}
}
}
..........................................................................................................
in both java and c the output will be
The Fibonacci numbers are: 0 1 1 2 3
...........................................................................................................
IF WE WANT THE USER TO INPUT THE NUMBERS:
USING C
#include<stdio.h>
int main()
{
int i, fibi1, fibi2, fibi3, k;
fibi1 = 0;
fibi2 = 1;
printf("enter the number of fibonacci numbers to generate: ");
scanf( "%d", &k );
printf( "The Fibonacci numbers are: " );
printf( "%d \t %d \t", fibi1, fibi2 );
for(i=0; i<k-2 ;i++)
{
fibi3= fibi1 + fibi2;
fibi1=fibi2;
fibi2=fibi3;
printf("%d \t", fibi3);
}
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int fibonacci;
System.out.print("enter the number of fibonacci numbers to generate:");
fibonacci= sc.nextInt();
int[] fibo = new int[fibonacci];
fibo[0] = 0;
fibo[1] = 1;
System.out.print("The Fibonacci numbers are: ");
System.out.print(" " + fibo[0] + " " + fibo[1]);
for(int i=2; i < fibonacci; i++)
{
fibo[i] = fibo[i-1] + fibo[i-2];
System.out.print(" " + fibo[i]);
}
}
}
Monday, October 27, 2014
How to swap any two numbers using C and java
12:21 PM
No comments
USING C
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
x=5;
y=6;
z=x;
x=y;
y=z;
printf(" the new first no is: %d ", x);
printf(" the new second no is: %d ", y);
// %d is use of integer type variables//
return 0;
}
USING JAVA
public static void main(String[] args)
{
int firstvalue = 5;
int secondvalue = 6;
int x = firstvalue;
firstvalue = secondvalue;
secondvalue = x;
System.out.println(" the new first no is: " + firstvalue);
System.out.println(" the new second no is: " + secondvalue);
}
..........................................................................................................
in both java and c the output will be
the new first no is: 6
the new second no is: 5
...........................................................................................................
IF WE WANT THE USER TO INPUT THE NUMBERS:
USING C
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
printf("Enter the first number:");
scanf("%d", &x);
printf("Enter the second number:");
scanf("%d", &y);
z=x;
x=y;
y=z;
printf(" the new first no is: %d ", x);
printf(" the new second no is: %d ", y);
// %d is use of integer type variables//
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int firstvalue;
int secondvalue;
System.out.print("Enter the first number:");
firstvalue= sc.nextInt();
System.out.print("Enter the Second number:");
secondvalue=sc.nextInt();
int z = firstvalue ;
firstvalue = secondvalue;
secondvalue = z;
System.out.println("the new first no is:" + firstvalue);
System.out.println("the new second no is:" + secondvalue);
}
}
Steps to construct a binary tree [data structure]
8:13 AM
No comments
Traversing of Binary tree can be done by as
(1) Preorder Traversing
(2) Inorder Traversing
(3) Postorder Traversing
Preorder traversal Steps
(1) Visit the root
(2) Traverse the left sub-tree in preorder
(3) Traverse the right sub-tree in preorder
Inorder traversal Steps
(1) Traverse the left sub-tree in inorder
(2) Visit the root
(3) Traverse the right sub-tree in inorder
Postorder traversal Steps
(1) Traverse the left sub-tree in postorder
(2) Traverse the right sub-tree in postorder
(3) Visit the root
(1) Preorder Traversing
(2) Inorder Traversing
(3) Postorder Traversing
Preorder traversal Steps
(1) Visit the root
(2) Traverse the left sub-tree in preorder
(3) Traverse the right sub-tree in preorder
Inorder traversal Steps
(1) Traverse the left sub-tree in inorder
(2) Visit the root
(3) Traverse the right sub-tree in inorder
Postorder traversal Steps
(1) Traverse the left sub-tree in postorder
(2) Traverse the right sub-tree in postorder
(3) Visit the root
Draw a binary search tree from the given sequence list the nodes in preorder traversal and inorder traversal [data structure]
2:05 AM
No comments
The following given sequences list the nodes of a binary search tree in preorder and inorder respectively
preorder: G, B, Q, A, C, K, F, P, D, E, R, H
inorder: Q, B, K, C, F, A, G, P, E, D, H, R
Sunday, October 26, 2014
Fun Magic programme
2:35 AM
No comments
USING C
#include<stdio.h>
#include<conio.h>
int main()
{
int z;
printf("Enter the number you want but don't say it to others:");
scanf("%d",&z);
printf("I can say the number you input without knowing it :-P \n");
printf("The number is: %d \n", z);
printf("lol :-P :-P ");
return 0
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int result;
System.out.print("Enter the number you want but don't say it to others:");
result= sc.nextInt();
System.out.print("I can say the number you input without knowing it :-P \n");
System.out.println("The number is: " + result);
System.out.print("\n lol :-P :-P :");
}
}
#include<stdio.h>
#include<conio.h>
int main()
{
int z;
printf("Enter the number you want but don't say it to others:");
scanf("%d",&z);
printf("I can say the number you input without knowing it :-P \n");
printf("The number is: %d \n", z);
printf("lol :-P :-P ");
return 0
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int result;
System.out.print("Enter the number you want but don't say it to others:");
result= sc.nextInt();
System.out.print("I can say the number you input without knowing it :-P \n");
System.out.println("The number is: " + result);
System.out.print("\n lol :-P :-P :");
}
}
Subscribe to:
Comments (Atom)
















