Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main(){
int g=DETECT,gmode;
initgraph(&g,&gmode,"C://TURBOC3//BGI");
setcolor(10);
setbkcolor(15);
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,5);
outtextxy(100,100,"HELLO WORLD!");
setcolor(20);
settextstyle(DEFAULT_FONT,HORIZ_DIR,5);
outtextxy(100,200,"HELLO WORLD!");
setcolor(25);
settextstyle(BOLD_FONT,HORIZ_DIR,5);
outtextxy(100,300,"HELLO WORLD!");
getch();
}
Output:
Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main(){
int g=DETECT,gmode;
initgraph(&g,&gmode,"C://TURBOC3//BGI");
line(10,90,300,90);
setcolor(10);
rectangle(10,100,300,250);
setcolor(30);
circle(100,180,50);
setcolor(15);
line(160,230,200,120);
line(200,120,240,230);
line(240,230,160,230);
getch();
}
Output:
Code:
package com.nearur;
import java.util.Scanner;
public class English {
String[] ones= {"","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","ninteen"};
String[] tens= {"","","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninty"};
StringBuffer buffer=new StringBuffer();
String c(int n) {
if(n<0) {
return "Minus "+c(-n);
}else if(n<20) {
return ones[n];
}else if(n<100) {
return tens[n/10]+" "+ones[n%10];
}else if(n<1000) {
return c(n/100)+" hundred "+c(n%100);
}else if(n<100000) {
return c(n/1000)+" thousand "+c(n%1000);
}else if(n<10000000) {
return c(n/100000)+" lakh "+c(n%100000);
}else if(n<1000000000) {
return c(n/10000000)+" crore "+c(n%10000000);
}
return "";
}
public static void main(String[] args) {
English a=new English();
Scanner in =new Scanner(System.in);
System.out.print("Enter Any Number : ");
int n=in.nextInt();
System.out.println(a.c(n).toUpperCase());
}
}
Output:
Code:
package com.nearur;
import java.util.Scanner;
public class NTB {
static StringBuffer buffer=new StringBuffer();
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.print("Enter Your Name:");
String a=in.nextLine();
String[] name=a.split(" ");
for(String x:name) {
convert(x);
}
System.out.println("Binary Code is : "+buffer.toString());
}
static void convert(String name) {
char[] a=name.toCharArray();
for(char x: a) {
binary((int)x);
buffer.append(" ");
}
}
static void binary(int n) {
while(n>0) {
if(n%2==0) {
buffer.append("0");
}else {
buffer.append("1");
}
n=n/2;
}
}
}
Output:
CODE:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main(){
int g=DETECT,gmode;
initgraph(&g,&gmode,"C://TURBOC3//BGI");
putpixel(100,100,10);
getch();
}
Output:
Following Code is Hangman Like game without graphics inspired by Duta http:duta.in:
Code:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
static String check="AEIOU";
public static void main(String[] args) {
ArrayList<String> questions=new ArrayList<>();
questions.add("ABRUPTLY");
questions.add("BOOKWORM");
questions.add("GALAXY");
questions.add("PNEUMONIA");
questions.add("STRONGHOLD");
questions.add("WHIZZING");
questions.add("PUZZLING");
questions.add("WRISTWATCH");
questions.add("ZODIAC");
questions.add("THUMBSCREW");
questions.add("YACHTSMAN");
questions.add("MNEMONIC");
questions.add("TRANSPLANT");
questions.add("RHYTHM");
questions.add("MICROWAVE");
Collections.shuffle(questions);
String ques=questions.get(0);
char[] given=new char[ques.length()];
int count=0;
for(int i=0;i<given.length;i++) {
if(varcheck(ques.charAt(i))) {
given[i]=ques.charAt(i);
}else {
given[i]='_';
}
}
boolean win=false;
Scanner in=new Scanner(System.in);
StringBuffer buffer=new StringBuffer();
outer:
while(count<7 && !win) {
for(int i=0;i<given.length;i++) {
System.out.print(given[i]+" ");
}
System.out.println();
System.out.println("Guess a Letter");
char c=in.nextLine().toUpperCase().charAt(0);
int i=0;
while(i<given.length) {
if(given[i]==c) {
System.out.println("Already Present in Word!!");
System.out.println("Guessed Letters : "+buffer);
System.out.println("Chances left : "+(7-count));
System.out.println("------------------------------");
continue outer;
}i++;
}
if(buffer.toString().contains(c+"")) {
System.out.println("Already Guessesed!!");
System.out.println("Guessed Letters : "+buffer);
System.out.println("Chances left : "+(7-count));
System.out.println("------------------------------");
continue outer;
}
if(ques.contains(c+"")) {
int idx=ques.indexOf(c);
while(idx>=0) {
given[idx]=c;
idx=ques.indexOf(c,idx+1);
win=true;
}
System.out.println("Good Guess!!");
}else {
count++;
System.out.println("Bad Guess!!");
}
buffer.append(c+",");
System.out.println("Guessed Letters : "+buffer.toString().substring(0,buffer.length()-1));
System.out.println("Chances left : "+(7-count));
for(char x: given) {
if(x=='_') {
win=false;
}
}
System.out.println("--------------------------------\n");
}
System.out.println("Word is : "+ques);
if(win) {
System.out.println("Congratulations,You win!!");
}else {
System.out.println("You Loose!!,Don't Worry Try Again");
}
in.close();
}
static boolean varcheck(char c) {
if(check.contains(c+"")) return true;
return false;
}
}
Output:
Following Code will give you desired number of quark pairs:
Code:
import java.util.Scanner;
public class MainQuark {
public static void main(String[] nt) {
System.out.print("Enter Value of N :");
int n;
Scanner in=new Scanner(System.in);
n=in.nextInt();
int count=0,i=1,num;
StringBuffer buffer=new StringBuffer();
while(count!=n) {
num=i;
int q=quark(num);
if(!prime(q)) {
for(int j=num+1;j<q;j++) {
if(q==quark(j)) {
buffer.append(i+"-"+j+"\n");
count++;
}
}
}
i++;
}
System.out.println("Pairs are\n"+buffer.toString());
}
static int quark(int n) {
int one=0,i=n;
while(n>0) {
if(n%2==1) {
one++;
}n=n/2;
}return one*(i);
}
static boolean prime(int n) {
for(int i=2;i<n/2;i++) {
if(n%i==0) return false;
}return true;
}
}
Output: