Saturday, November 22, 2008

C PROGRAM TO CHECK STRING PALINDROME

STRING PALINDROME

#include"string.h"
void main()
{
  char *str,*rev;
  int i,j;
  clrscr();
  printf("\nEnter a string:");
  scanf("%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();

C CODE FOR SWAPING OF TWO ARRAYS

C CODE FOR SWAPING OF TWO ARRAYS

void main()
{
  int a[10],b[10],c[10],i;
  clrscr();
  printf("Enter First array->");
  for(i=0;i<10;i++)
  scanf("%d",&a[i]);
  printf("\nEnter Second array->");
  for(i=0;i<10;i++)
            scanf("%d",&b[i]);
  printf("Arrays before swapping");
  printf("\nFirst array->");
  for(i=0;i<10;i++)
  {
            printf("%d",a[i]);
  }
  printf("\nSecond array->");
  for(i=0;i<10;i++)
  {
            printf("%d",b[i]);
  }
  for(i=0;i<10;i++)
  {
            //write any swapping technique
            c[i]=a[i];
            a[i]=b[i];
            b[i]=c[i];
  }
  printf("\nArrays after swapping");
  printf("\nFirst array->");
  for(i=0;i<10;i++)
  {
            printf("%d",a[i]);
  }
  printf("\nSecond array->");
  for(i=0;i<10;i++)
  {
            printf("%d",b[i]);
  }
  getch();
}

C PROGRAM FOR CONVERSION OF BINARY TO DECIMAL

CONVERSION OF BINARY TO DECIMAL

void main()
{
  long int no,n=0,j=1,rem,no1;
  clrscr();
  printf("Enter any number any binary form->");
  scanf("%ld",&no);
  no1=no;
  while(no!=0)
  {
            rem=no%10;
            n=n+rem*j;
            j=j*2;
            no=no/10;
  }
  printf("\nThe value of binary no. %ld is ->%ld",no1,n);
  getch();
}

C CODE FOR CONVERSION OF DECIMAL TO BINARY

C PROGRAM CONVERSION OF DECIMAL TO BINARY

void main()
{
  int n,m,no=0,a=1,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 %d in binary is->",m);
   printf("%d",no);
  getch();
}

C PROGRAM FORSECOND SMALLEST NUMBER IN AN UNSORTED ARRAY

 SECOND SMALLEST NUMBER IN AN UNSORTED ARRAY

main()
{
  int un[10], i, s1, s2;
  clrscr();
  printf("Enter array elements: ");
  for ( i = 0; i < 10; ++i )
            scanf("%d", &un[i]);
  s1 = un[0];
  for ( i = 1; i < 10; ++i )
  {
            if ( s1 > un[i] )
                        s1 = un[i];
            if ( s1 != un[0] )
                        s2 = un[0];
            else
                        s2 = un[1];
  }
  for ( i = 1; i < 10; ++i )
  {
            if ( s1 != un[i] && s2 > un[i] )
                        s2 = un[i];
  }
  printf("\nSecond smallest: %d", s2);
  return 0;
}

SECOND LARGEST NUMBER IN AN UNSORTED ARRAY c program

SECOND LARGEST NUMBER IN AN UNSORTED ARRAY

main()
{
  int un[10], i, big1, big2;
  printf("Enter array elements: ");
  for ( i = 0; i < 10; ++i )
            scanf("%d", &un[i]);
  big1 = un[0];
  for ( i = 1; i < 10; ++i )
  {
            if ( big1 < un[i] )
                        big1 = un[i];
            if ( big1 != un[0] )
                        big2 = un[0];
            else
                        big2 = un[1];
  }
  for ( i = 1; i < 10; ++i )
  {
            if ( big1 != un[i] && big2 < un[i] )
                        big2 = un[i];
  }
  printf("Second largest: %d\n", big2);
  return 0;

C PROGRAM FOR LARGEST NUMBER IN AN ARRAY

LARGEST  NUMBER IN  AN ARRAY

void main()
{
int a[50],size,i,large;
clrscr();
printf("\nEnter the size of the array: ");
scanf("%d",&size);
printf("\nEnter %d elements in to the array: ”, size);
for(i=0;i
scanf("%d",&a[i]);
big=a[0];
for(i=1;i
{
if(large=a[i];
}
printf("\nBiggest: %d",large);
getch();
}

C CODE TO DELETE ELEMENT FROM AN ARRAY AT DESIRED POSITION

DELETE ELEMENT FROM AN ARRAY AT DESIRED POSITION

void main()
{
  int a[50],i,pos,size;
  clrscr();
  printf("\nEnter size of the array: ");
  scanf("%d",&size);
  printf("\nEnter %d elements in to the array: ",size);
  for(i=0;i             scanf("%d",&a[i]);
  printf("\nEnter position where to delete: ");
  scanf("%d",&pos);
  i=0;
  while(i!=pos-1)
            i++;
  while(i<10)
  {
            a[i]=a[i+1];
            i++;
  }
  size--;
  for(i=0;i             printf(" %d",a[i]);
  getch();
}

C PROGRAM TO DELETE THE VOWELS FROM A STRING

DELETE  THE  VOWELS  FROM  A  STRING C PROGRAM

void main()
{
char str[20],s[20];
int i,j=0;
clrscr();
printf("Enter any string->");
scanf("%s",str);
printf("The string is->%s",str);
for(i=0;i<=strlen(str);i++) { if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u') str[i]=' '; else s[j++]=str[i]; } s[j]='\0'; printf("\nThe string without vowel is->%s",s);
getch();
}

C CODE TO PRINT FIBONACCI SERIES

C  CODE  TO PRINT  FIBONACCI SERIES

void main()
{
  int i=0,j=1,k=2,r,f;
  clrscr();
  printf("Enter the number range:");
  scanf("%d",&r);
  printf("\n required FIBONACCI SERIES: ");
  printf("%d %d",i,j);
  while(k   {
            f=i+j;
            i=j;
            j=f;
            printf(" %d",j);
            k++;
  }
  getch();
}

C-PROGRAM FACTORIAL OF A NUMBER

 TO FIND  FACTORIAL OF A NUMBER

void main()
{
  int i=1,f=1,num;
  clrscr();
  printf("\nEnter a number:");
  scanf("%d",&num);
  while(i<=num)
  {
            f=f*i;
            i++;
  }
  printf("\nFactorial of %d is:%d",num,f);
  getch();
}

SWAPPING OF STRINGS in c-program

 C-program for SWAPPING OF STRINGS

void main()
{
  int i=0,j=0,k=0;
  char str1[20],str2[20],temp[20];
  clrscr();
  puts("Enter first string");
  gets(str1);
  puts("Enter second string");
  gets(str2);
  printf("Before swaping the strings are\n");
  puts(str1);
  puts(str2);
  while(str1[i]!='\0')
  {
             temp[j++]=str1[i++];
  }
  temp[j]='\0';
  i=0,j=0;
  while(str2[i]!='\0')
  {
              str1[j++]=str2[i++];
  }
  str1[j]='\0';
  i=0,j=0;
  while(temp[i]!='\0')
  {
              str2[j++]=temp[i++];
  }
  str2[j]='\0';
  printf("After swaping the strings are\n");
  puts(str1);
  puts(str2);
  getch();
}