Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

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!

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.

Sunday, October 25, 2009

Software bug

A software bug is the common term used to describe an error, flaw, mistake, failure, or fault in a computer program or system that produces an incorrect or unexpected result, or causes it to behave in unintended ways. Most bugs arise from mistakes and errors made by people in either a program's source code or its design, and a few are caused by compilers producing incorrect code. A program that contains a large number of bugs, and/or bugs that seriously interfere with its functionality, is said to be buggy.

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
How about some bugs for snacks?

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();
}

Wednesday, October 21, 2009

#include<stdio.h>
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

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);
}
}

Following is a program that was given to my juniors in the C-Debugging finals. It was quite surprising that no one solved it, in an efficient manner!

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!

Monday, September 7, 2009

Today, I was speaking with my Internet Programming lecturer, Mr. Gupta. He was sharing his experience on teaching C to the first year mechanical class. He said, he couldn't explain the logic of adding sum of n digits to a student. He employed the usual strategy of leaving out the nines in the number. (The student didn't know that simple logic it seems!)

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.

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.

Tuesday, April 7, 2009

My former object oriented programing lecturer Mr.Nandhakumar wanted me to help with his project in which path generation was a part. For a given sequence directed graph I had to generate all possible paths from the start node to the end nodes and I tried it out. It took nearly an hour to finish this program. It's quite understandable from the comments I have added to the program!


#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;
}

Sunday, June 8, 2008

WORDCOUNT

Wordcount is my third game and I would rate it as the best of the three.





Screenshots of Wordcount game

There are two levels in this game.

  1. Frame the word.
  2. Find the word.

Frame the word

  1. You begin the game by choosing either a vowel or a consonant.
  2. After choosing 9 letters, your count down starts!!!
  3. Within one minute,you have to form a word using the letters (not necassarily all the letters) in the letter pool.
  4. Use each letter in the pool only once!
  5. You score based on the length of your word and maximum length possible.
  6. 5 times this level is played!

Find the word

  1. This is simple jumble solving.
  2. It is a seven letter jumble (with no letter repeating).
  3. Within 30 seconds you have to solve the jumble.
  4. 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

Friday, June 6, 2008

Well, in recent past I had been working only with VB, I had not done anything else and my second game after toggler has turned out to be more advanced, I have concentrated on theGUI of the game and I think I have succeeded to a great extent in that, the game is ROCK PAPER SCISSORS!









Screenshots of the game

The game is pretty simple.

Player has the full range of throws to play, as follows :

  1. He/she can select one of the three, rock or paper or scissors.
  2. Rock wins against scissors, loses to paper and stalemates against itself.
  3. Paper wins against Rock, loses to scissors and stalemates against itself.
  4. Scissors wins against paper, loses to rock and stalemates against itself.
  5. You get one point for every win and your opponent gets one point for his/her win!!!
  6. 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.

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!!!

Wednesday, June 4, 2008

All these days I had been working on few VB projects.That is the reason for me not posting in my blog!This post would be on the softwares(small softwares) I developed.
The softwares that I developed are:
  1. Torrent timer
  2. SD's Alarm Clock
  3. SDPAD
  4. Key Catcher
  5. Toggler
Torrent Timer:






Screen shots of Torrent timer

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.

Monday, January 21, 2008

#include stdio.h
#include conio.h
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!!!

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.

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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/*
Name: GROUPING PROGRAM
Copyright: SD
Author: Deepak Senthilkumar
Date: 06/12/07 14:56
Description: It is a program to group numbers based on the sum of digits!!!
*/
#include stdio.h
/*
These header files are not required in dev c++...But they are requred in Turbo c/c++
#include stdlib.h
#include conio.h
#include alloc.h
*/

struct table
{
int num;
struct table *next;
};

struct table a[9];

int digitsum(int num)
{

int sum,temp,n;
temp=0;
n=num;
sum=0;

while(n>0)
{

temp=n%10;
sum=sum+temp;
n=n/10;

}

return sum;

}


int tdigitsum(int num)
{

int tsum;
tsum=digitsum(num);
if(tsum>9)
tsum=digitsum(tsum);
tsum=digitsum(tsum);
return tsum;
}
void input()
{

int inum,isum;
struct table *newn,*curr;
printf("\n\nEnter a number:");
scanf("%d",&inum);
isum=tdigitsum(inum);
curr=&a[isum];
while(curr->next!=NULL)
curr=curr->next;
newn=(struct table *)malloc(sizeof(struct table));
newn->num=inum; newn->next=NULL;
curr->next=newn;
}

void display()
{

int i;
struct table *curr;
for(i=1;i<10;i++)//>
{
curr=&a[i];
curr=curr->next;
while(curr!=NULL)
{
printf("%d ",curr->num);
curr=curr->next;
}

}

}


int main()
{

int choice,check;
check=0;
printf("\nWELCOME TO MY PROGRAM OF GROUPING THE NUMBERS BASED ON SUM OF DIGITS!!!!\n");
do
{

printf("\n\nMENU\n\n 1. INSERT \n 2. DISPLAY\n 3. EXIT\n");
printf("\nENTER CHOICE : ");
scanf("%d",&choice);
switch(choice)
{

case 1:

input();
check=1;
break;

case 2:

if(check)
display();
else printf("\n\nNothing there to be displayed\n");
break;

case 3:

exit(0);

}

}while(1);
return 0;

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


What do you think about the program?

Post your suggestions!

Sunday, November 4, 2007

Code converter

The code converters are very rare.And this code converter converts C# code to VB.NET and vice versa.It is an excellent code converter tool.My dream project is an all language code converter.When I saw this i felt very interested.Check it out.Type some code,Convert and verify!!!!


Check it out!!!