Friday, October 2, 2009

ADA 5th sem lab prgms

Prgm no 5b
#include
#include
#include
int size, array[5][5],p,q,r;
void algorithm()
{
for(r=1;r<=size;++r)
for(p=1;p<=size;++p)
for(q=1;q<=size;++q)
if((array[p][r]+array[r][q]) < array[p][q])
array[p][q]=array[p][r]+array[r][q];
}
void main()
{
printf("enter the size of graph");
scanf("%d",&size);
printf("enter graph data");
for(p=1;p<=size;++p)
for(q=1;q<=size;++q)
{
scanf("%d",&array[p][q]);
if(array[p][q]==0)array[p][q]=999;
}
algorithm();
printf("shortest path");
for(p=1;p<=size;++p)
{
for(q=1;q<=size;++q)
printf("/t %d",array[p][q]);
printf("/n");
}
}

ADA 5th sem lab prgms

/* Program No. 5a
Write A C Program to find the topological ordering of vertices in the given grapgh*/
#include
#include
void main()
{
int p,q,r,vertices,num[10][10],x[10],t[10],calc=0;
printf("Enter the number of vertices: ");
scanf("%d",&vertices);
printf("Enter the Adjacency Matrix:\n");
for(p=1;p<=vertices;p++)
for(q=1;q<=vertices;q++)
scanf("%d",&num[p][q]);
for(p=1;p<=vertices;p++)
x[p]=0,t[p]=0;
for(p=1;p<=vertices;p++)
for(q=1;q<=vertices;q++)
x[p]+=num[q][p];
printf("The Topological order is: \n");
while(calc {
for(r=1;r<=vertices;r++)
if((x[r]==0)&&(t[r]==0))
{
printf("%d\t",r);
t[r]=1;
calc++;
for(p=1;p<=vertices;p++)
if(num[r][p]==1)
x[p]--;
}
}
}
/* Output:
Enter the number of vertices: 6
Enter the Adjacency Matrix:
0 0 1 1 0 0
0 0 0 1 1 0
0 0 0 1 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 0
The Topological order is:
1 2 3 4 5 6
...*/



ADA 5th sem lab prgms

/* Program No: 4.
Sort a given set of elements using the Selection Sort method..*/
#include
#include
int x[10], num;
void algorithm()
{
int m,n,situation,low,var;
for(m=0;m {
low=x[m];
situation=m;
for(n=m+1;n if(x[n] {
low=x[n],situation=n;
var=x[situation];
x[situation]=x[m];
x[m]=var;
}
}
}
void main()
{
int m,n;
printf("ENTER THE NUMBER OF ELEMENTS\n");
scanf("%d",&num);
printf("----------------------------------\n");
printf("ENTER THE %d ELEMENTS\n",num);
printf("----------------------------------\n");
for(m=0;m scanf("%d",&x[m]);
algorithm();
printf("-------------------------------------\n");
printf("THE SORTED ELEMENTS ARE\n");
printf("-------------------------------------\n");
for(m=0;m printf("%d\n",x[m]);
printf("***********************\n");
getche();
}
/*
Output:
ENTER THE NUMBER OF ELEMENTS
4
----------------------------------
ENTER THE 5 ELEMENTS
----------------------------------
20
10
40
30
-------------------------------------
THE SORTED ELEMENTS ARE
-------------------------------------
10
20
30
40
***********************
*/

ADA 5th sem lab prgms

Prgm no.3
/*Sort a given set of elements using the Merge Sort method..*/
#include
#include
int num[10], x[10];
void algorithm(int small, int s, int big)
{
int m,n,p;
p=small;
m=small;
n=s+1;
while((m<=s)&&(n<=big))
{
if(x[m] num[p++]=x[m++];
else
num[p++]=x[n++];
}
while(m<=s)
num[p++]=x[m++];
while(n<=big)
num[p++]=x[n++];
for(m=small;m<=p-1;m++)
x[m]=num[m];
}
void sort(int small,int big)
{
int s;
if(small {
s=(small+big)/2;
sort(small,s);
sort(s+1,big);
algorithm(small,s,big);
}
}
void main()
{
int i,n;
clrscr();
printf("Enter the number of Elements\n");
scanf("%d",&n);
printf("Enter the Elements\n");
for(i=0;i scanf("%d",&x[i]);
sort(0,n-1);
printf("The Sorted Element are\n");
for(i=0;i printf("%d\n",num[i]);
getche();
}

/*
Output:
Enter the number of Elements
5
Enter the Elements
20
10
50
40
30
The Sorted Element are
10
20
30
40
50
*/

ADA 5th sem lab prgms

/* Program No: 02.
Sort a given set of elements using the Heap Sort method..*/
/* C program to sort a given list of numbers using Heap Sort*/
#include
#include
int num[50], elements=0, old, new;
int highest(int num[])
{
int m, max=0, index;
for(m=1;m<=elements+1;m++)
if(max max=num[m],index=m;
num[index]=0;
return max;
}
int compare(int a, int b)
{
if(num[a]==0&&num[b]==0)
return -1;
if(num[a]>num[b])
return 0;
else
return -1;
}
void exchange(int a, int b)
{
int temp;
temp=num[a];
num[a]=num[b];
num[b]=temp;
}
void insert(int new)
{
int k;
elements++;
num[elements]=new;
k=elements;
while(k>1)
{
old=k/2;
if(compare(k,old)>=0)
break;
exchange(k,old);
k=old;
}
}
void rem()
{
int k=1,new;
printf("%d\n",num[1]);
num[1]=highest(num);
while((2*k)<=elements)
{
if(num[2*k]==0||num[2*k+1]==0)
{
if(num[2*k]==0)
new=2*k+1;
else
new=2*k;
}
else
if(compare(2*k,2*k+1)<0)
new=2*k;
else
new=2*k+1;
if(compare(k,new)<0)
break;
exchange(k,new);
k=new;
}
}
void main()
{
int a,i,n,par=0;
clrscr();
printf("input the number of elements\n");
scanf("%d",&n);
printf("input the %d elements\n",n);
for(i=0;i {
scanf("%d",&a);
insert(a);
}
printf("sorted order is\n");
for(i=0;i rem();
par=highest(num);
printf("%d\n",par);
getche();
}

/* Output:
input the number of elements
5
inter the 5 elements
64
24
46
84
28
sorted order is
24
28
46
64
84
..........*/

ADA 5th sem lab prgms

/* Program No. 1 (b)
C Program to search an element using Linear Search and to find the time taken to search an element..*/
#include
#include
#include
int num[20], max, element, m;
void ls(int m)
{
if(element==num[m])
{
printf("Element is available at the position: %d\n", m+1);
return;
}
if(element>=max)
{
printf("Element is not available\n");
return;
}
ls(m+1);
}
void main()
{
clock_t start, end;
clrscr();
printf("Enter the array size\n");
scanf("%d",&max);
printf("Enter the array elements\n");
for(m=0;m
scanf("%d",&num[m]);
printf("Enter the element to be searched\n");
scanf("%d",&element);
start=clock();
ls(0);
end=clock();
printf("Time taken for linear search is %f",(end-start)/CLK_TCK);
}

Sunday, August 23, 2009

BE 5 th sem ADA lab programs

/* Program No. 1(a)
C Program to serach an element using binary search...*/
#include
#include
#include
int num[20], max, e, small, big, v, m,n,ans;
void receve()
{
printf("Enter the elements of the array\n");
for(m=0;m scanf("%d",&num[m]);
printf("Enter the elements to be searched: ");
scanf("%d",&e);
}
void show()
{
printf("The sorted array is\n");
for(m=0;m printf("%d\t",num[m]);
printf("\n");
ans=bs(0,max-1);
if(ans==(-1))
printf("Element not found\n");
else
printf("Element found at position: %d",ans+1);
}
void bsort()
{
for(m=0;m for(n=0;n if(num[n]>num[n+1])
{
v=num[n];
num[n]=num[n+1];
num[n+1]=v;
}
}
int bs(int small, int big)
{
int mid=(small+big)/2;
if(small>big)
return -1;
else if(e>num[mid])
return bs(mid+1,big);
else if(e return bs(small, mid-1);
else
return mid;
}
main()
{
clock_t start, end;

printf("Enter the size of the array\n");
scanf("%d",&max);
receve();
start=clock();
bsort();
end=clock();
show();
printf("The time was: %f",(end-start)/CLK_TCK);

getche();
return;
}

Saturday, August 22, 2009

Microsoft's Browser Best at Beating Malware

Microsoft's Internet Explorer 8 (IE8) again trounced rival browsers in a test of their malware-blocking abilities, catching 81% of attack code-infected sites, according to a testing company.



Artwork: Chip TaylorIE8's skills at sniffing out malware sites improved by 17% since March, said Rick Moy, president of NSS Labs, the firm that conducted the benchmarks. The testing was sponsored by Microsoft's security team.

IE8's improvement, and its dominance over competitors, could make some users reconsider their decision to abandon Microsoft's browser for one of its challengers. "Should people rethink that decision?" Moy asked. "By [this] data, absolutely."

While IE8 blocked eight of 10 of the malware-distributing sites that NSS included in its 12-day test, the nearest competitor, Mozilla's Firefox 3.0, caught just 27% of the same sites. Apple's Safari 4.0 and Google's Chrome 2.0, meanwhile, blocked only 21% and 7% of the sites, respectively. Opera Software's browser properly identified only 1%.

"I think it comes down to resources and the focus of these companies," Moy said in an interview, referring to Microsoft's ability to out-spend rivals on such things as security research and malicious site investigations. "The more researchers you have, the better you'll do. Microsoft has a certain amount of paranoia [about security] because of its footprint of services that get attacked all the time, like Hotmail, and it has the money to hire really smart people."

Opera, which performed the poorest in the malware-blocking benchmarks, is an example on the other end of the spectrum, said Moy. "What resources do they really have to bring to the problem?" Moy said. "There's a lot that can't be solved with software, but requires the human element."

NSS tested five Windows-based browsers -- IE8, Firefox 3.0.11, Safari 4.0.2, Chrome 2.0.0.172.33 and Opera 10 beta -- against more than 2,100 malware sites in 69 test runs over 12 days. Like the tests NSS Labs ran last March, the sites were so-called "socially engineered" malware sites, the type that trick users into downloading attack code. Typically, the download is disguised, often as an update to popular software such as Adobe's Flash Player.

The tests did not include sites that launch "drive-by" attacks that don't require user interaction, an increasingly common tactic by hackers who often infect legitimate sites with kits that try a number of different exploits in the hope of compromising an unpatched browser or PC.

To defend against the kind of sites that NSS tested, browser makers have added anti-malware features to their software. Microsoft, for instance, has aggressively touted its SmartScreen Filter, a new malware-detection feature in IE8.

All browsers that include such a tool -- or anti-phishing tools, which operate in a similar fashion -- rely on a "blacklist" of some sort. The list, which includes known or suspected malware sites, is used to display warnings before a user reaches a site, but after the URL is typed in.

"The foundation is an in-the-cloud reputation-based system that scours the Internet for malicious sites," explained Moy, "then adds them to a black list or white list, or assigns them scores." The browser then uses that information to block or allow access to a site.

IE8 significantly improved its lead over other browsers since March, Moy noted, with its browser's malware-blocking rate up 12 percentage points -- a 17% improvement -- while rivals' scores declined across the board. Firefox dropped three percentage points, for example, as did Safari 4; Chrome fell eight percentage points and Opera, four.

Even though Firefox, Safari and Chrome all rely on the same data source for their anti-malware blacklists -- Google's SafeBrowsing API -- their scores varied considerably, something Moy thought was due to each browsers' use of the list. "Google produces the API, but that doesn't mean all the browsers consume the data in the same way at the same time," he said. "We don't have any visibility on how many people are looking at the [SafeBrowsing] data, but clearly Firefox must be adding other things to it."

Moy also said that IE8's anti-malware protection improved over time at a greater rate than did its rivals. Because NSS Labs tested every four hours, it was able to measure how quickly each browser reacted, and blocked, a new threat introduced into the test. While IE8's score jumped from 51% on Day Zero -- the day the infected site debuted on the Internet -- to 91% by Day 5 (a 40 point jump), Firefox was only able to muster a 10-point increase, from 14% to 24%. Chrome improved the most over the course, starting at just 3% on Day Zero and ending at 14% on Day 5.

"I was surprised when Microsoft got 69% in the first study," said Moy. "Then they went from 69% to 81." NSS hopes to repeat the test before the end of the year.

According to the most recent data from Web metrics vendor Net Applications, IE8 accounted for 12.5% of all browsers used in July, representing 18% of all versions of IE in use.

The NSS report can be downloaded from the company's Web site ( download PDF).

Saturday, May 9, 2009

File structures lab program 1 (for 6th sem ISE)

#include stdio.h
#include conio.h
#include iostream.h
#include fstream.h
#include string.h
#include stdlib.h
class string
{
char str[30];
public:string()
{
strcpy(str,0);
}
void stringrev();
void read();
friend ostream & operator <<(ostream &s,string p)
{
s<< p.str<<"\n";
return s;
}
};

void string::read()
{
cout<<"enter the name:\n";
gets(str);
}
void string::stringrev()
{
strrev(str);
}

main()
{
string s[20];
int ch;
char str[20];
clrscr();
for(;;)
{
cout<<"\n1:standard i/o \n2:using a file \n3:exit";
cout<<"\n enter the choice\n";
cin>>ch;
switch(ch)
{
case 1:cout<<"enter the no. of names to insert\n";
int n;
cin>>n;
for(int i=0;i {
s[i].read();
}
cout<<"\n reversed strings\n";
for(i=0;i {
s[i].stringrev();
cout< }
break;

case 2:fstream ofile,ifile,ofile1;
ofile.open("in.txt",ios::out);
cout<<"enter the no. of strings:\n";
cin>>n;
for(i=0;i {
cout<<"enter the string\n";
cin>>str;
ofile< }
ofile.close();
ifile.open("in.txt",ios::in);
ofile1.open("out.txt",ios::out);
char buf[30];
while(!ifile.eof())
{
ifile.getline(buf,80,'\n');
strrev(buf);
cout< ofile1< }
break;

case 3:exit(0);
}
}
}