Solution of your query in c language


Solution of your query in c language

Welcome to ask query 

(q)
date 9/4/08
Hi!
I hope u will be fine.plz help in following program. I need source code.

The question is: A string (e.g.: "I am writing an email") is entered through the keyboard, write a program in C to get its reverse in a column as output i.e.:

email
an
writing
am

Answer:

Code for such program is:

void main()
{
char str[20];
char *ptr=str,*temp;
int i=0,j;
clrscr();
scanf("%[^\n]",str);
while(*ptr){
i++;
ptr++;
}
for(j=0;j
            if(*ptr==' ')
            {
                  temp=ptr;ptr--;temp++;
                  while((*temp!=' ')&&(*temp!='\0')) {
                       printf("%c",*temp);
                        temp++;
                  }
                  printf("\n");
            }
            else
            {
                  ptr--;
            }
}
while(*ptr!=' ') {
printf("%c",*ptr);
ptr++;
}
getch();
}

(q)
I want a C program to check whether a string is a palindrome or not where the string to be checked is passed as command line argument during execution.
(pahal ray
8/25/08

Answer:

#include"string.h"
void main(int counter,char**string)
{
char *rev;
char str[15];
int i,j;
clrscr();
strcpy(str,string[1]);
printf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
getch();
}

(q)
How to write a c program to display the source code of the program?
(ramya)
8/23/08
Answer: 
If source code is available 
#include"stdio.h"
void main()
{
   char str[70];
   FILE *p;
   clrscr();
 if((p=fopen("mod.c","r"))==NULL)
   {
      printf("\nUnable t open file string.txt");
      exit(1);
   }
   while(fgets(str,70,p)!=NULL)
            puts(str);
   fclose(p);
   getch();
}

(q) Swapping of two number without using third variable

Answer

void main()
{
int a=5,b=10;
clrscr();
//process one
a=b+a;
b=a-b;
a=a-b;
printf("a= %d  b=  %d",a,b);

//process two
a=5;b=10;
a=a+b-(b=a);
printf("\na= %d  b=  %d",a,b);
//process three
a=5;b=10;
a=a^b;
b=a^b;
a=b^a;

printf("\na= %d  b=  %d",a,b);
//process four
a=5;b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na= %d  b=  %d",a,b);
//process five
a=5,b=10;
a=b+a,b=a-b,a=a-b;
printf("\na= %d  b=  %d",a,b);
getch();
}

(q) How to convert decimal to binary in c program?

Answer:

void main()
{
  long int m,no=0,a=1;
  int n,rem;
  clrscr();
  printf("Enter any decimal number->");
  scanf("%d",&n);
  m=n;
  while(n!=0)
  {
          rem=n%2;
          no=no+rem*a;
          n=n/2;
          a=a*10;
  }
   printf("The value %ld in binary is->",m);
   printf("%ld",no);
  getch();
}
Post a Comment