Re: [algogeeks] Print Hello infinite..................
#include void print1(); void print2() { printf("Hello\n"); print1(); } void print1() { printf("Hello\n"); print2(); } int main() { print1(); } On Thu, Mar 10, 2011 at 11:47 AM, nidhi jain wrote: > > > @abhishek:isn't it recursion? > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
[algogeeks] Explain the o/p
#include main() { long x; float t; scanf("%f",&t); printf("%d\n",t); x=90; printf("%f\n",x); { x=1; printf("%f\n",x); { x=30; printf("%f\n",x); } printf("%f\n",x); } x==9; printf("%f\n",x); } o/p on gcc compiler 20.3 (i/p given) -1073741824 20.299988 20.299988 20.299988 20.299988 20.299988 plz explain the o/p -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: printing without loop
use recursion. On Tue, Mar 1, 2011 at 5:13 PM, bittu wrote: > here we go > > void main() > { > int i; > > i=1; > > loop: > printf("%d", i) > (i<100)? i++: return 0; > go to loop; > > } > > Thanks & Regards > Shashank Mani >> "The Best Way to Escape From The Problem is to Solve > it" > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: arrays
#include #include int main() { int a[20],i,n,max,t,j,k; printf("Enter the no. of elements\n"); scanf("%d",&n); for(i=0;i=max) { max=a[j]; k=j; j--; } else j--; } t=a[i]; a[i]=a[k]; a[k]=t; } for(i=0;i wrote: > Move-To-The-Front. > > On Sep 27, 11:58 pm, Anand wrote: > > Given an array of integers, for each index i, you have to swap the value > at > > i with the first value smaller than A[ i ] that comes after index i > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: ReVerse a string using recursion
@albert why r u asking for a non optimal solution?? On Sat, Sep 25, 2010 at 11:24 PM, albert theboss wrote: > please let me know solution using extra memory. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- :-) ********* Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Number problem
Here's the code int rem_dup(int n) { int *a,i,c,t,d,count[10]={0},arr[20],j=0,sum=0; a=(int *)malloc(sizeof(a)); for(i=0;n>0;i++)//storing each digit of number in an array { a[i]=n%10; n=n/10; } c=d=i-1; i=0; while(i wrote: > @Saurabh: Doesn't this turn 10 into 1? You need to count the digits in > the number as you are reversing it, and replace the second while loop > with a for loop with that many iterations. > > Dave > > On Sep 21, 11:28 pm, saurabh agrawal wrote: > > @dave: > > your code is producing 4526 for input=24526 instead of 2456 > > Here's corrected code :) > > /CODE/// > > int function(int n){ > > int a[10]={0},temp=0,result =0; > > while(n){ //reverse the number.. > > temp=10*temp+n%10; > > n/=10; > > } > > n=temp; > > while(n){ ///remove duplicate digits... > > if(a[n%10]==0){ > > a[n%10]=1; > > result=10*result+n%10; > > } > > n/=10; > > } > > return result;} > > > > ///END/ > > > > > > > > On Wed, Sep 22, 2010 at 8:51 AM, Dave wrote: > > > @Saurabh: Doesn't your code turn 123 into 321? Try this: > > > > > int function(int n) > > > { > > >int a[10]={0}; > > >int result=0; > > > int place=1; > > > while(n){ > > >if(a[n%10]==0){ > > >a[n%10]=1; > > > result+=(n%10)*place; > > >place*=10; > > >} > > >n/=10; > > >} > > >return result; > > > } > > > > > Dave > > > > > On Sep 21, 3:12 pm, saurabh agrawal wrote: > > > > int function(int n){ > > > > > > int a[10]={0}; > > > > int result =0; > > > > while(n){ > > > > if(a[n%10]==0){ > > > > a[n%10]=1; > > > > result=10*result+n%10; > > > > } > > > > n/=10;} > > > > > > return result;` > > > > > > } > > > > On Wed, Sep 22, 2010 at 12:39 AM, Albert > > > wrote: > > > > > Given a number find the number by eliminating the duplicate digits > in > > > > > the number.. > > > > > > > for eg: 24526 ans is 2456 > > > > > . > > > > > > > int function(int n) > > > > > { > > > > > > > . > > > > > . > > > > > . > > > > > > > } > > > > > > > Give all sort of solutions to this problem. > > > > > > > Efficiency in the code is important > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > Groups > > > > > "Algorithm Geeks" group. > > > > > To post to this group, send email to algoge...@googlegroups.com. > > > > > To unsubscribe from this group, send email to > > > > > algogeeks+unsubscr...@googlegroups.com > > > > > > > > > . > > > > > For more options, visit this group at > > > > >http://groups.google.com/group/algogeeks?hl=en.-Hide quoted text - > > > > > > - Show quoted text - > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Algorithm Geeks" group. > > > To post to this group, send email to algoge...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > algogeeks+unsubscr...@googlegroups.com > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Number problem
@yellow your code turns 1000,100,10,2270,12130 to 1,1,1,27,123 repectively simply it removes all trailing zeros ... On Wed, Sep 22, 2010 at 8:10 PM, Yellow Sapphire wrote: > My Solution. > > Almost same as above but the flag is set by using bits. > > #define SETFLAG(flag, pos) (flag=flag | (1< #define IS_FLAG_SET(flag,pos) (flag & (1< > int remove_dup(int n) > { >int temp=0, temp2=0; >unsigned int flag=0; > >/* > * Reverse the number > */ >while (n>0 && (temp=temp*10 + n%10), n=n/10); > >/* > * Find duplicates by setting the bits in the flag > */ >n=temp; >temp=0; >while (n>0) { >temp2=n%10; >if(!IS_FLAG_SET(flag, temp2)) { >temp=temp*10 + temp2; >SETFLAG(flag, temp2); >} >n=n/10; >} >return temp; > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: ReVerse a string using recursion
i dont think that without giving 1st and last index, this is possible.i m using i and j as 1st and last index respectively On Sat, Sep 25, 2010 at 1:00 AM, albert theboss wrote: > sorry i dont know the solution. > i just expecting such answer > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- .... :-) ***** Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: ReVerse a string using recursion
@albert i think you know the solution and u r just testing others.so post the solution and stop this discussion.. On Sat, Sep 25, 2010 at 12:48 AM, albert theboss wrote: > @nishanth : > could u give me any solutions without global variable or static > variable > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
@Albert i think this should be right static int i=0; int j; void xstrrev(char *s) { char t; if(i==0) j=strlen(s)-1; if(iwrote: > Ur function prototype is not similar to one i posted before > > check it out > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
i am giving the full code #include #include #include void xstrrev(char *s , int i , int j) { char t; if(i wrote: > @nishant: > what is i and j..??? > @ > > On Thu, Sep 23, 2010 at 1:20 PM, Nishant Agarwal < > nishant.agarwa...@gmail.com> wrote: > >> void xstrrev(char *s , int i , int j) >> { >> char t; >> if(i> { >> t=s[i]; >> s[i]=s[j]; >> s[j]=t; >> xstrrev(s,i+1,j-1); >> >> } >> } >> >> On Thu, Sep 23, 2010 at 11:29 PM, Albert wrote: >> >>> How to reverse a String using recursion in C without using any extra >>> memory? >>> >>> the question seems to be simple. >>> >>> char* strrev(char *) >>> { >>>... >>>... >>>... >>> } >>> >>> >>> Try to give all the answers for this prototype. >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algoge...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >>> >> >> >> -- >> :-) >> * >> Nishant Agarwal >> Computer Science and Engineering >> NIT Allahabad >> * >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] ReVerse a string using recursion
void xstrrev(char *s , int i , int j) { char t; if(i wrote: > How to reverse a String using recursion in C without using any extra > memory? > > the question seems to be simple. > > char* strrev(char *) > { >... >... >... > } > > > Try to give all the answers for this prototype. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Re: Print 1 to n one per each line on the standard output
try in linux.it is working fine On Thu, Sep 23, 2010 at 8:58 PM, coolfrog$ wrote: > @Greed > in windows.. output is infinite loop and printing... > 0 > 0 > 0 > 0 > 0 > ... infinite loop.. > > > On Thu, Sep 23, 2010 at 9:57 AM, Greed wrote: > >> You can use setjmp ,longjmp or goto to get desired result. >> #include >> #include >> void print(int v) >> { >>int i=0; >> >>jmp_buf env; >> >>setjmp(env); >>if(i<=v) >>{ >>printf("%d\n",i); >>++i; >>longjmp(env,1); >>} >> } >> >> >> int main() >> { >>int n; >>scanf("%d",&n); >>print(n); >> } >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] sum of primes
http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes On Thu, Sep 23, 2010 at 5:45 PM, Debajyoti Sarma wrote: > How to find the sum of prime numbers between 1 and 1. > I don't expected traversal of the whole range and find primes and sum > uping > Any other logic is there?? i think we need deep mathematics for this . > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- .... :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] do this: two numbers with min diff
int minDiff(int arr[], int arr_size) { int min_diff = arr[1] - arr[0]; int max_element = arr[0]; int i; for(i = 1; i < arr_size; i++) { if(arr[i] - max_element < min_diff) min_diff = arr[i] - max_element; if(arr[i] > max_element) max_element = arr[i]; } return min_diff; } On Mon, Sep 20, 2010 at 10:38 AM, Srinivas wrote: > 2 nos with min diff > given an array of size n. find 2 numbers from array whose difference > is least in O(n) w/o > using xtra space( i mean constant space) > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] Print 1 to n one per each line on the standard output
void print_number(int n) { if(n<=100) { printf("%d\n",n); print_number(n+1);} } main() { int n=1; print_number(n);} this code is using recursion only.not loops, goto and switch if anyone can do it without recursion then please post ur algo... On Wed, Sep 22, 2010 at 9:19 PM, Divesh Dixit < dixit.coolfrog.div...@gmail.com> wrote: > Write an algorithm that will print 1 to n, one per each line on the > standard output, where n is > a integer parameter to the algorithm. An algorithm should not use > while, for, do-while > loops, goto statement, recursion, and switch statement. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
Re: [algogeeks] A help please
output will be 2 garbage_value scanf returns numbers of inputs taken from std input and since there should be 2 arguments in printf according to the format, so garbage value will print On Wed, Sep 22, 2010 at 2:25 PM, rahul rai wrote: > "printf("%d%d",scanf("%d%d",&a &b))" > > -- > Rahul K Rai > rahulpossi...@gmail.com > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- :-) * Nishant Agarwal Computer Science and Engineering NIT Allahabad * -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.