QwertyManiac said:That swapping thing cost me 6 marks in an exam last year (In C). The teacher refused to believe it works, and when I showed it in the lab, she said its not the right way to do it People ..
Download digit.txt below to view code.
You can rename it to digit.cpp.
Sorry for the inconvenience
harsh@qwerty-workstation:~$ ./digit.out
Digit Forum URL Bulleted List Generator
-------------------------------------
Version 1.0
The Input file must be in the format of Title first and URL next.
Example:
Title1
*URL 1
Title 2
*URL 2
And so on..
Enter the input file's location and name to convert: title
Enter the output file's location and name to store into: digitout
Enter the list name: Programs
harsh@qwerty-workstation:~$
Nav11aug said:^^ better algo than the one given..
11 @aditya.shevade
Projjwal said:@aditya.shevade It's very cool ans.Gr8 job ...I was just looking for this ans.
Now do the same thing without using "()" .
use Bitwise Operators
--------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
a=12;
b=25;
a=((b-a)+(b=a));
printf("\na:%d\nb:%d",a,b);
getch();
}
This is de C version of aditya.shevade run it.
-----------------------------------------------------------
Projjwal said:This is de C version of aditya.shevade run it.
harsh@qwerty-workstation:~$ python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=25
>>> b=10
>>> [B]a,b=b,a[/B]
>>> a
10
>>> b
25
>>> exit()
harsh@qwerty-workstation:~$
better thanaditya.shevade said:Uhh... better than one given where? Please explain what do you mean.
the implementation did not use the line b=a+b.thz why i said "better"Projjwal said:b=a+b;
a=b-a;
b=b-a;
---------------de above program has 3 functional lines now write it in one functional line.
The_Devil_Himself said:Hey guys(and gals of course) don't you think this thread should be made a sticky?The starter please start a poll man--sticky or not sticky.
#include <stdio.h>
#define M 10
void bsearch(int list[],int n,int element)
{
int l,u,m, flag = 0;
l = 0;
u = n-1;
while(l <= u)
{
m = (l+u)/2;
if( list[m] == element)
{
printf("The element whose value is %d is present at position %d in list\n",element,m);
flag =1;
break;
}
else
if(list[m] < element)
l = m+1;
else
u = m-1;
}
if( flag == 0)
printf("The element whose value is %d is not present in the list\n",element);
}
void readlist(int list[],int n)
{
int i;
printf("Enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&list[i]);
}
void printlist(int list[],int n)
{
int i;
printf("The elements of the list are: \n");
for(i=0;i<n;i++)
printf("%d\t",list[i]);
}
void main()
{
int list[M], n, element;
printf("Enter the number of elements in the list max = 10\n");
scanf("%d",&n);
readlist(list,n);
printf("\nThe list before sorting is:\n");
printlist(list,n);
printf("\nEnter the element to be searched\n");
scanf("%d",&element);
bsearch(list,n,element);
}