Rahul.menon 0 Light Poster

use strcmp function

Rahul.menon 0 Light Poster

HI
deepak.hm123
the code will the desired output

void strev(char str[])
{
int I,len=strlen(str);//strlen give length of string
for(I=0;len=len-1; I>=len;I++;len--)
{
char temp;
temp=str[I];
str[I]=str[len];
str[len]=temp;
}
)

This doesnt work swapping wont do the job. if u input the "good boy" in str,
it would give "yobd oog".o/p must be "boy good" . this logic does not discriminate words. would work for singleword. for single word the logic using swap is

void strev(char str[])
{
int I,len=strlen(str);//strlen give length of string
int le = len;
char temp;
for(I=0,len=len-1; I<=le/2;I++,len--)
{
temp=str[I];
str[I]=str[len];
str[len]=temp;
}
printf("%s",str);
}
Rahul.menon 0 Light Poster

ok

Rahul.menon 0 Light Poster

I will make modification after some hour

Great if u could come up with short and simple one

Rahul.menon 0 Light Poster

I got it must have been A++ line 25

Rahul.menon 0 Light Poster

If you need an explanation on the concepts of string reversing, I have a very detailed explanation in this post:

http://www.daniweb.com/forums/thread313164.html

its diffrnt from reversing string logic, it cannot be applied here. the position of words have to be reversed

Rahul.menon 0 Light Poster

Here's my code

void main()
{
 char str[60],str1[60];
 int i = 0,j=0,k=0,end =0;
 clrscr();
 gets(str);

 while(i<strlen(str))
 {
  if(str[i] == ' ' || !str[i+1])
  {
     str1[k] = ' ';
     k++;

     if(!str[i+1])
	i++;

     for(j = i-1;j>=end;j--)
       {
	str1[k]= str[j];
	k++;
       }
     end = i;
   }
   i++;
 }

   k--;
   for(;k>0;k--,printf("%c",str1[k]));
}

Its adding some extra spaces i will check and find.
if have got some better code pls tell.

Rahul.menon 0 Light Poster

I didnt unterstand one thing gender being a string how can u compare it with char 'f'
"while(Summary.gender != 'F' && Summary.gender != 'M' || strlen(Summary.gender) > 1)" - here
it shld be
while(srtcmp(Summary.gender,"F" > 0)
or
while(Summary.gender != 'F' && Summary.gender != 'M' || strlen(Summary.gender) > 1)

just check this code-

struct str
{
 char gen[100];
};
struct str str1;
void main()
{

  gets(str1.gen);
  if(str1.gen[0]=='m')
  {
   printf("Correct");
  }

}
Rahul.menon 0 Light Poster
progneer.soft the pattern is 
         Aa
      Cc Bb
   Dd Ee Ff
jj Ii Hh Gg

and not
         Aa
      Cc Bb
   Ff Ee Dd
Jj Ii Hh Gg

I want the exact code my code is putting the small letters in right sequence,prblm is the bigs. Ideally it shdnt have been.
Rahul.menon 0 Light Poster

Got one sample.
% Preallocate the 256-by-256-by-1-by-20 image array.
X = repmat(int16(0), [256 256 1 20]);

% Read the series of images.
for p=1:20
filename = sprintf('brain_%03d.dcm', p);
X(:,:,1,p) = dicomread(filename);
end

% Display the image stack.
montage(X,[])

For Dicomm images, Matlab provide a good c Api's. I would prefer u to Use Python for it.

Rahul.menon 0 Light Poster

Please check out This
Output required

Aa
      Cc Bb
   Dd Ee Ff
jj Ii Hh Gg
#include<stdio.h>
#include<conio.h>
void main()
{
 char a = 'a',a1 ='a',A = 'A',A1='A';
 int i,j,n;
 clrscr();
 for(i =1;i<=4;i++,printf("\n"))
 {
   if(i%2!=0)
   for(j = 1;j<=i;j++)
   {
       printf("%c%c ",a,A);
       a++;
       A++;
   }
   else
   {
    a1 = a-1;
    A1 = A-1;
   for(n = i;n>=1;n--)
    {
     printf("%c%c ",a1+n,A1+n);
     a++;
     A1++;
    }
   }
  }

}

Its comming partial right. That is small letters follow the pattern but big ones aren't.

Rahul.menon 0 Light Poster
//Declare an str
char str[50],str1[50];
accept
gets(str);
for(init to end of str;>0;var--)
store str1[1] = str[n]
print str1;
Rahul.menon 0 Light Poster

It should have been summary.Gender. array of struct to be declared summary[3] or any thing.

Rahul.menon 0 Light Poster

splitting is not problem. problem is reading after split 99.99 becomes 99&0.99 '%' doesn't work for 0.99 - illegal use of float points. i have to know the length of num to mul it by 10 to make it int. if there is any other logic behind / or % pls tell.

Rahul.menon 0 Light Poster

Thanx Adak Good Explanation

Rahul.menon 0 Light Poster

I wanna write a code which would add the digits before decimal and after decimal.
eg:- 12.22 would add upto 3.4 , 491.941 would give 5.5

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
  double a1[5],a ; //array of 5 numbers
  int b,len,i,sum=0,cnt = 0;
  char ch[10];

  for(i = 0;i<5;i++)  // accept numbers
  scanf("%lf",&a1[i]);

  while(cnt<5)
  {
	a = a1[cnt];
	 b = (int)(a);   //numbers before float
	 a = a  - (int)(a);  //remaining number
	 sprintf(ch,"%lf",a); //copy to string


	 while(b)
	  {
		 sum += b%10; 
		 b/=10;
	  }
	 if(sum >= 10)
	  {
		 sum = (sum % 10) + (sum /10); //if the resultants sum is a two digit num                            //convert it to single digit (assuming sum to be two digit)  
	  }
  printf("\n%d .",sum);
  sum = 0;
  i = 2;

	while(ch[i])
	 {

		sum += ch[i] - '0';
		i++;
	 }
	if(sum >= 10)
	 {
	  sum = (sum % 10) + (sum /10);
	 }

	 printf("%d",sum);
	 sum = 0;
	 cnt++;
  }
}

Similar thing can be done by reading it as string array.
But i wanted to know if it could be done without using string array or string functn. plainly by using any numeric datatype.

Rahul.menon 0 Light Poster

My doubt was how the order of sel sort algo becomes n^2(ref in wiki,cprg.com....) whereas it shows linear behaviour. for 4 elements, irrespective of order the iterations are 6 for 5-10 and so on. its never square.

Rahul.menon 0 Light Poster
#include<stdio.h>
#include<conio.h>

void main()
{
  int num[50],i,i1,j,temp = 1,cnt = 0;
  printf("How many elements ");
  scanf("%d",&i);
  printf("Enter the elements ");
  for(j = 0;j<i;j++)
	{
	 scanf("%d",&num[j]);
	}

	i1 = 0;
	j=1;
	while(i1 < i )
	{
		for( ;j<i;j++)
		  {                    
			if((num[j] < num[i1])&& (i1<i))
			  {
				 temp = num[j];          //algorithm for sel sort
				 num[j] = num[i1];
				 num[i1] = temp;
			  }
			  cnt++;   //counting iterations
		  }
		  i1++;
		  j=1;
		  j+=i1;
	}
	for(j = 0 ;j<i;j++)
	 printf("\n%d",num[j]);

	 printf("\n%d ",cnt);
}

Hi,
the sel sort algorithm takes n^2 time as per the wiki and what is taught generally(pls correct if wrong) .
where each element is checked every time(i:e loop runs n*n times and values are swapped) . but when i modified the code a bit the algo becomes log n and running more efficiently than bubble sort. so is it that the change has changed meaning and its no more selection sort.

Rahul.menon 0 Light Poster

I Wanted some good patterns questions that is challenging. Also some logic teasing questions. forums like codechef have questions bit too absurd to understand. It would be really good if someone could provide questions easy to understand yet logically challenging.

Rahul.menon 0 Light Poster

The key to the game is that if you are at any time, needing to move a stack or substack, you will use the following:

1) if the stack/sub stack has an odd number of disks, you'll move the disk in question to the goal needle

2) otherwise, you'll move the disk to the non-goal needle

This IS a classic recursive program example, but it can be done iteratively, of course. Step through your code with say, two disks, and make sure that's working right. Then, step up to three disks, and go from there.

Find out exactly where it's failing - and what logic is causing it.

The Code is working but i want to really shorten it either by better logic other than the abstract code or recursive code..

Rahul.menon 0 Light Poster
#include<stdio.h>
#include<conio.h>
#include<math.h>
int a[70]; //src disk array
int b[70];//temp disk array
int c[70];//tar disk array
int val, srcval=1,tempval=0,tarval=0;
int es[3] = {1,1,0}; //array to decide iteration of disks from and to
int et[3] = {1,0,1};
int etr[3]= {0,1,1};
int os[3] = {1,1,0};
int ot[3] = {0,1,1};
int otr[3]= {1,0,1};
void find();//to keep the update of elements on top(srcval,tempval,tarval)
void move(int[],int[]);//to move from src to tar
void main()
{
 int i1 =0;
 long int j1;
 int *src;
 int *temp;
 int *tar;
 printf("Enter The number of disks");
 scanf("%d",&val);

 if(val % 2 == 0) //even no of disk
 {
	src =  es; 
	temp = et;
	tar = etr;
 }
 else   //odd no of disk
  {
	 src = os;
	 temp = ot;
	 tar = otr;
  }
  for(j1 = 1;j1<=val;j1++)
  {
	 a[j1-1]=j1;
	 b[j1-1]=0;
	 c[j1-1]=0;
  }
  for(j1 = 1;j1<=(long)(pow(2.0,val)-1);j1++)
  {
	getch();
	 if(src[i1]==1&&tar[i1]==1)
	  {
		 if(srcval > tarval )
		 {
		  if(tarval == 0)
		  {
		  printf("Source to target");
				  move(a,c);
		  }
		  else{
				  printf("target to source");
				  move(c,a); }
		 }
		 else
		 {

		  if(srcval==0){
			  printf("Target to source");
				  move(c,a);
				  }
				  else{
				  printf("source to target");
				  move(a,c);
				  }
		 }

	  }

	  if(src[i1]==1&&temp[i1]==1)
		  {
			if(srcval>tempval)
			{

			if(tempval==0)
			  {
				  printf("source to temperory");
				  move(a,b);
			  }
				  else
				  {
				  move(b,a);
					printf("temperory to source ");
				  }
			}
				else
				{
				if(srcval == 0)
				{
				  move(b,a);
					printf("temperory to source ");
				}
				  else
				  {
				  move(a,b);
				  printf("source to temperory");
				  }
				}
		  }
		if(temp[i1]==1&&tar[i1]==1)
		  {
				if(tempval>tarval )
				{
				  if(tarval==0)
				  {
				  printf("temperory to target");
				  move(b,c);
				  }
				  else
				  {
				  printf("target to temperory");
				  move(c,b);
				  }
				}
				else
				{
				  if(tempval==0)
				  {
					 printf("target to temperory");
					move(c,b);
				  }
				  else
				  {
					 printf("temperory to …
Rahul.menon 0 Light Poster

Well sakthi i would say that the efficiency was what i was looking for
there are numerous ways. the one which u said would uses 3 nested loops
which would again bring a linear growth in algorithm (n^6 times). the previous i posted was also linear but only 2n iterations. if there is a shorter version and efficient i would be interested.

Rahul.menon 0 Light Poster

This is the only logic i could derive.
Pls tell if anything better could be done
void main()
{
char a = 'a';
int i,j,l=0;
clrscr();
for(i=1;i<=6;i++,printf("\n"))
{
for(j=0;j<i;j++)
{
if(i%2==0)
printf("%c ",a+j);
else
{
printf("%c ",a+=l);
if(i>2 && j>=2)
l=6;
else
l=4;
}
}
a = 'a';
l=0;
}
}

Rahul.menon 0 Light Poster

Actually this is a question from computer management Question paper,
But i feel the use of array is inevitable

Rahul.menon 0 Light Poster

#

include <stdio.h>

int main()
{
	int n;
	cout<<"            *********************************"<<endl;
	cout<<"            *************Problem3************"<<endl;
	cout<<"            *********************************"<<endl<<endl<<endl;

	cout<<"        Please type and odd integer greater than 1"<<endl;
	
	cin>>n;

	if(n%2==0)
	{


		cout<<"YOU DID NOT TYPE AN ODD INTEGER !!!"<<endl;
	}
	else
	{
		if(n==1)
		{
			cout<<"YOU NEED AN ODD INTEGER GREATER THAN 1 !!!"<<endl;
		}
		else
		{
			for(int i=(n-1)/2;i>0;i--)
			{
				for(int j=(n-1)/2;j>i;j--)
				cout<<" ";
				for(int k=0;k<i;k++)
				cout<<" *";
				cout<<"\n";
			}
			for(int i=0;i<(n-1)/2+1;i++)
			{
				for(int j=(n-1)/2+1;j>i;j--)
				cout<<" ";
				for(int k=0;k<i;k++)
				cout<<" *";
				cout<<"\n";
			}

half of triangle is done... will have to repeat the same again for another part

Rahul.menon 0 Light Poster

how to print the below triangle without using arrays

a
a b
a e i
a b c d
a e i o u

Rahul.menon 0 Light Poster

I hope above code is simple to understand
Rahul Menon

Rahul.menon 0 Light Poster
#include<stdio.h>
void main()
{
int i,j,cnt=0,k,sp;

for(i = 1;i<=7;i++,printf("\n"))
  {
     k = i;
     for(sp = 7;sp>=i;sp--)
          printf("  ");
    for(j = 1;i>1?j<=(i+cnt):j<=i;j++)
        {
             printf("%d ",k);
             if(j<i)
             k-=1;
             else
             k+=1;
        }
        cnt++;
    }
 }