Saturday, August 4, 2012
Today I learnt something new in SQL Queries..
Thot I could share with you ppl!
I was running
query a (select col1 from table1)>> execution time 3 secs
query b (select col1 from table2)>> execution time 5 secs
query a intersect query b
(select col1 from table1 intersect select col1 from table2)>> execution time 16 mins!
Lot of technicalities and reasons are there for this behavior... but quick fix is as follows
select col1 from table1 where rownum>0
intersect
select col1 from table2 where rownum>0 >> execution time 6 secs!
Labels: Programming
Tuesday, December 8, 2009
I did not understand the storage of float in C/C++ until I have executed this program by accident.
#include<iostream.h>
#include<conio.h>
void main()
{
int i;
clrscr();
float f=0.7;
cout.precision(10);
cout<<f;
getch();
}
OUTPUT
0.6999999881
Now I understand the program
if(0.7f==0.7)
printf("I love you");
else
printf("I hate you");
The output is I hate you. I was under the false impression that it was due to the size. but it is not. It is due to the precision actually.
0.7=0.7000000000 which is not equal to 0.7f=0.6999999881!
Now it makes sense. I prepared so many questions like this for my Cognizant interview. But this is the only one that I remember now.
Labels: Programming
Sunday, October 25, 2009
Common types of computer bugs
Conceptual error (code is syntactically correct, but the programmer or designer intended it to do something else)
Maths bugs
- Division by zero
- Arithmetic overflow or underflow
- Loss of arithmetic precision due to rounding or numerically unstable algorithms
Logic bugs
- Infinite loops and infinite recursion
- Off by one error, counting one too many or too few when looping
Syntax bugs
Use of the wrong operator, such as performing assignment instead of equality test. In simple cases often warned by the compiler; in many languages, deliberately guarded against by language syntax
Resource bugs
- Null pointer dereference
- Using an uninitialized variable
- Access violations
- Resource leaks, where a finite system resource such as memory or file handles are exhausted by repeated allocation without release.
- Buffer overflow, in which a program tries to store data past the end of allocated storage. This may or may not lead to an access violation. These bugs can form a security vulnerability.
- Excessive recursion which though logically valid causes stack overflow
Co-programming bugs
- Deadlock
- Race condition
- Concurrency errors in Critical sections, Mutual exclusions and other features of concurrent processing. Time-of-check-to-time-of-use (TOCTOU) is a form of unprotected critical section.
Teamworking bugs
- Unpropagated updates; e.g. programmer changes "myAdd" but forgets to change "mySubtract", which uses the same algorithm. These errors are mitigated by the Don't Repeat Yourself philosophy.
- Comments out of date or incorrect: many programmers assume the comments accurately describe the code
- Differences between documentation and the actual product
Labels: Programming
Thursday, October 22, 2009
#include<stdio.h>
void main()
{
int a;
clrscr();
a=(scanf("%d",&a)+a-1)+(scanf("%d",&a)+a-1);
printf("%d",a);
getch();
}
Labels: Programming
Wednesday, October 21, 2009
void main()
{
int a=3,b=2,c;
c=printf("%*d%*d",a,1,b,1);
clrscr();
printf("%d",c);
getch();
}
To understand more about this printf, Click here
Labels: Programming
Saturday, October 10, 2009
An interesting java program that caught my attention is the one that follows!import java.awt.BorderLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
public class ScrollSample {
public static void main(String args[]) {
String title = "JScrollPane Sample";
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Icon icon = new ImageIcon("dhoni.jpg");
JLabel label1 = new JLabel(icon);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(label1
);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
}
Labels: Java, Programming
Only Vivek and Sathish from third year did some justice to the program!
#include<stdio.h>
void main()
{
int x;
char c,h;
clrscr();
printf("\n Enter a character:");
scanf("%c", &c);
printf(" The first character entered was:%c",c);
printf("\n Enter another character:");
scanf("%c",&h);
printf("\n The second character entered was:%c",h);
getch();
}
Solution:
#include<stdio.h>
void main()
{
int x;
char c,h;
clrscr();
printf("\n Enter a character:");
scanf("%c", &c);
fflush(stdin);
printf(" The first character entered was:%c",c);
printf("\n Enter another character:");
scanf("%c",&h);
printf("\n The second character entered was:%c",h);
getch();
}
Explanation:
stdin, gets the character and the enter as another character and it is set to h.
So h is not input at all!
fflush is an interesting function which flushes the unwanted content from the stream!
In java too we face this problem, I will get back to that in my tutorial!
Labels: Deepak's Scribble, Programming
Monday, September 7, 2009
That's when this idea struck me. If you have a number, say x.
It shall be represented as (9*n)+y.
If we identify y then that's the sum of digits.
Say the number is 103
It's simple 99+4, (9*11)+4 hence 4.
y is nothing but (9+9+9+9....11 times) +4
So we skip all those nines and take the 4 alone.
In simpler words if x is the number then (x modulus 9) is the sum of the digits.
So in a programmer's perspective its just x%9.
Labels: Programming
Monday, June 1, 2009
In VB.Net there's a feature for commenting multi lines. The toolbox has the provision for that. It is one handy feature in .net.
Labels: Programming
Tuesday, April 7, 2009
#include<stdio.h>
#include<conio.h>
void findpath(int);//function to find the path
void printpath();//function to print the path
int graph[13][13]=
//0 1 2 3 4 5 6 7 8 9 10 11 12
{0,1,0,0,0,0,0,0,0,0,0 ,0 ,0,//0
0,0,1,1,0,0,0,0,0,0,0 ,0 ,0,//1
0,0,0,0,0,0,0,0,0,0,0 ,1 ,0,//2
0,0,0,0,1,1,1,0,0,0,0 ,0 ,0,//3
0,0,0,0,0,0,0,0,0,0,0 ,1 ,0,//4
0,0,0,0,0,0,0,0,0,0,0 ,1 ,0,//5
0,0,0,0,0,0,0,1,0,0,0 ,0 ,0,//6
0,0,0,0,0,0,0,0,1,0,0 ,0 ,0,//7
0,0,0,0,0,0,1,0,0,1,1 ,0 ,0,//8
0,0,1,0,0,0,0,0,0,0,0 ,1 ,0,//9
0,0,0,0,0,0,0,0,0,0,0 ,0 ,1,//10
0,0,0,0,0,0,0,0,0,0,0 ,0 ,0,//11
0,0,0,0,0,0,0,0,0,0,0 ,0 ,0};//12
int i=0,j=0,k=0,temp=0;//k--->acts as a pointer to the queue cur path
int start_node=0;//stores the start node
int path[13][13];//stores the paths available
int curpath[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};//queue of the path formed
int final[13]={0,0,0,0,0,0,0,0,0,0,0,1,1};//final state or not
int tot_paths[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};//total paths available from a state
int path_count[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};//paths that have been traversed
int flag_cycle;//it is a flag which is set to 1 if the current path has a cycle
int previ;
void main()
{
clrscr();
for(i=0;i<13;i++)
{
printf("\nPath %d:",i);
k=0;
for(j=0;j<13;j++)
{
path[i][j]=0;
if(graph[i][j]!=0)
{
printf("%d,",j);
tot_paths[i]++;
path[i][k++]=j;
}
}
}
printf("\n\n\nThe paths available are:\n");
findpath(start_node);
printpath();
for(temp=k-1;temp>=0;temp--)
{
if(tot_paths[curpath[temp]]<=path_count[curpath[temp]])
{
path_count[curpath[temp]]=0;
curpath[temp]=0;
k--;
}
else
{
k--;
findpath(curpath[temp]);
printpath();
}
}
getch();
}
void findpath(int start)
{
int count;
i=start;
count=path_count[i];
while(!final[i])//while final state is not reached
{
//check whether there is a cycle in the graph,if so skip it
if(checkpath(i))
{
curpath[k]=i;
i=previ;
return;
}
curpath[k++]=i;//add the node in the queue
path_count[i]++;//increment the path count
previ=i;
i=path[i][count];//move to the next node
count=path_count[i];//update count
}
//the same process is repeated for the final state
curpath[k++]=i;
path_count[i]++;
i=path[i][count];
count=path_count[i];
k--;
}
void printpath()//when this fn. ends temp should be equal to k
{
int temp1;
//check whether this path contains a cycle
//if so skip it
for(temp1=0;temp1<k;temp1++)
{
if(curpath[k]==curpath[temp1])
{
temp=k;
return;
}
}
printf("\n");
for(temp=0;temp<k;temp++)//don't change this variable temp,it is a global
variable!
{
printf("%d--->",curpath[tem]);
}
printf("%d",curpath[temp]);
}
int checkpath(int value)//checks whether there is a cycle
{
int temp1;
for(temp1=0;temp1<k;temp1++)
{
if(value==curpath[temp1])
return 1;
}
return 0;
}
Labels: Programming
Sunday, June 8, 2008
Screenshots of Wordcount game
There are two levels in this game.
- Frame the word.
- Find the word.
Frame the word
- You begin the game by choosing either a vowel or a consonant.
- After choosing 9 letters, your count down starts!!!
- Within one minute,you have to form a word using the letters (not necassarily all the letters) in the letter pool.
- Use each letter in the pool only once!
- You score based on the length of your word and maximum length possible.
- 5 times this level is played!
Find the word
- This is simple jumble solving.
- It is a seven letter jumble (with no letter repeating).
- Within 30 seconds you have to solve the jumble.
- If it is correct you score 200 points.
Your final score is out of 700 points.
This is an acid test to your vocabulary skills!
This game is loosely based on the COUNT DOWN game which runs on channel 4 in UK.
Download link: http://kctcse.googlepages.com/WORDCOUNT.ZIP
Labels: Deepak's Scribble, Programming
Friday, June 6, 2008
Screenshots of the game
The game is pretty simple.
Player has the full range of throws to play, as follows :
- He/she can select one of the three, rock or paper or scissors.
- Rock wins against scissors, loses to paper and stalemates against itself.
- Paper wins against Rock, loses to scissors and stalemates against itself.
- Scissors wins against paper, loses to rock and stalemates against itself.
- You get one point for every win and your opponent gets one point for his/her win!!!
- Final winner is the one who scores the maximum points (set at the start of the game) first!!!
It's between you and the computer!
Download link: http://kctcse.googlepages.com/ROCKPAPERSCISSORS.zip
Try the game give your comments on the game.
I am waiting for your comments.
Labels: Deepak's Scribble, Programming
Thursday, June 5, 2008
Screen shot of the Type Racer - Hack!
I am now really happy! I developed a crack to the type racer application in orkut. I set the speed to 85 words per minute because that would sound more realistic. If the speed goes above 100, the type racer asks image verification (very big CAPTCHA). So this is better. You would definitely love this crack to type racer.
I am happy because I atlast developed an internet oriented application!!!
It is a small 130 kb file!!!
Labels: Deepak's Scribble, Programming
Wednesday, June 4, 2008
The softwares that I developed are:
- Torrent timer
- SD's Alarm Clock
- SDPAD
- Key Catcher
- Toggler
This software was the birth of my need to download torrents. My net plan
allows me unlimited download from 2 AM to 8 AM. So I had to wake up early in
the morning to switch on the net, to stop that, I came with the idea of
torrent timer. If you mention the hours and minutes after which the download
should start, this software will start the download automatically. It can
also be used to any other file/software also. I have added an audio player
with this software and the interface has been developed keeping the end
user’s comfort in mind.
Note:
When a playlist of format “.wpl” is opened a special playlist navigator opens
making the audio player user friendly.
Download link: http://kctcse.googlepages.com/TORRENTTIMER.zip
SD's Alarm Clock:
Screen shot of SD's Alarm Clock
It is a simple alarm clock with the feature of adding a music file as the alarm tone.
While enetering the date and time the correct format has to be maintained, otherwise the clock may not work as you desire.
SDPAD:
Screenshot of SDPAD
SDPAD is the replica of notepad! The additional feature is that you can change the color and fonts with better effect than in notepad!!!
Download link: http://kctcse.googlepages.com/SDPAD.zip
Key Catcher:
Screen Shots of key catcher
Off all the softwares I developed, this is the best one.
You can rename the key catcher as SYSTEM because in task manager, this would sound better!!! This software will store the keys pressed in your system when it is running! It will also store the active windows running in the system once every minute. You can hide the key catcher so that it runs invisibly!
Download link: http://kctcse.googlepages.com/KEYCATCHER.zip
TOGGLER:
Screen shot of toggler
This is the first game I had ever developed using VB(any language for that matter).
It is a simple game.
The goal of the game is to turn all the buttons from [X] to [.]. This is done by clicking. When a button is clicked, its state is toggeled, but so is the state of four buttons around it, so plan carefully!
Download link: http://kctcse.googlepages.com/TOGGLER.zip
You download these softwares, work with them and comment on the softwares.
Labels: Deepak's Scribble, Programming
Monday, January 21, 2008
#include
#include
int main(void)
{
float A,Bb,D,G,F;
A = 440;
G = 780;
Bb = 461;
D = 586;
F = 687;
sound(G); delay(500); nosound(); sound(G); delay(250); nosound(); sound(G); delay(250); nosound(); sound(G); delay(500); nosound(); sound(2*D); delay(500); nosound(); sound(2*A); delay(250); nosound(); sound(2*Bb); delay(250); nosound(); sound(2*A); delay(250); nosound(); sound(G); delay(250); nosound(); sound(F); delay(500); nosound(); sound(2*A); delay(500); nosound(); sound(G); delay(250); nosound(); sound(2*A); delay(250); nosound(); sound(G); delay(250); nosound(); sound(F); delay(250); sound(G); delay(250); sound(2*A); delay(250); sound(2*Bb); delay(500); sound(2*A); delay(500); sound(G); delay(250); sound(F); delay(250); sound(D); delay(500); nosound();
sound(G); delay(500); nosound(); sound(G); delay(250); nosound(); sound(G); delay(250); nosound(); sound(G); delay(500); nosound(); sound(2*D); delay(500); nosound(); sound(2*A); delay(250); nosound(); sound(2*Bb); delay(250); nosound(); sound(2*A); delay(250); nosound(); sound(G); delay(250); nosound(); sound(F); delay(500); nosound(); sound(2*A); delay(500); nosound(); sound(G); delay(250); nosound(); sound(2*A); delay(250); nosound(); sound(G); delay(250); nosound(); sound(F); delay(250); sound(G); delay(250); sound(2*A); delay(250); sound(2*Bb); delay(500); sound(2*A); delay(500); sound(G); delay(250); sound(F); delay(250); sound(D); delay(500); nosound();
//end 2
sound(2*A); delay(250); nosound(); sound(G); delay(250); nosound(); sound(F); delay(250); sound(G); delay(250); sound(2*A); delay(250); sound(2*Bb); delay(500); sound(2*A); delay(500); sound(G); delay(250); sound(F); delay(250); sound(D); delay(500); nosound();
//end 3
sound(2*A); delay(250); nosound(); sound(G); delay(250); nosound(); sound(F); delay(250); sound(G); delay(250); sound(2*A); delay(250); sound(2*Bb); delay(500); sound(2*A); delay(500); sound(G); delay(250); sound(F); delay(250); sound(D); delay(500); nosound(); return 0;
}
This source code is not mine but probably the best that you could ever see....
It plays the airtel music!!!
Labels: Programming
Thursday, December 13, 2007
My friend asked me to check this program out.
I learnt something new trying it out.
Hope you learn something too.
PROGRAM:
#define square(x) x*x
#include
int main()
{
int x;
x=5;
char *p;
p="%d\n";
printf(p,100);
char *w[]={"Kct","yahoo","google"};
printf("%s",*w+4);
printf("\n%d",square(x));
printf("\n%d",square(x+1));
printf("\n%d",square(++x));
getchar();
return 0;
}
OUTPUT:
100
yahoo
25
11
49
*The output is from Dev c++ compiler.
Labels: Programming
Thursday, December 6, 2007
After blogging and collecting informations for my story,I felt very bored.It has been quite a while since I programmed.So I did a c program(my favorite language) to group numbers based on the sum of digits(finally truncated to a single digit).I learnt hashing last year.But never really tried it out.In my sem I had a similar program where I had to group numbers based on the number of digits that repeat in that number.So I did this program as a time pass.
int digitsum(int num)
{
void display()
int main()
case 1:
case 2:
case 3:
exit(0);
}while(1);
Labels: Programming
Sunday, November 4, 2007
Check it out!!!
Labels: Programming