Saturday, November 22, 2008

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();
}