Friday, October 11, 2019

c++

C
CPP
#include<iostream>
#include<conio.h>
#include<string.h>
 using namespace std;
  int BinToDec(char bin[])
    {
     int dec=0,base=1,temp,len,i=0;
      for(i=strlen(bin)-1;i>=0;i--)
       {
        temp=int(bin[i])-48;
         dec=temp*base+dec;
        base*=2; 
    }
     return dec;
 }
   int main()
    {
     char bin[7];
     cout<<"Enter a binary No.:-";
     cin>>bin;
     int bn=BinToDec(bin);
     cout<<"Decimal No.="<<bn;
     getch();
    }
#include<stdio.h>
#include<string.h>
   /* char* Delete(char str[],int p)
  {
    	int i;
    	for(i=p-1;i<strlen(str);i++)
  	   	 str[i]=str[i+1];
		return str;
	}*/
	void Delete(char str[],int p)
     {
    	int i;
    	for(i=p-1;i<strlen(str);i++)
  	   	 str[i]=str[i+1];
	}
 int main()
  {
  	char str[100],*str1,ch;
	int i,j,length;
  	printf("Enter a string:-");
  	scanf("%s",str);
  	printf("Enter the character you want to delete a character:-");
  	fflush(stdin);
    scanf("%c",&ch);
    printf("Before deletion  = %s\n",str);
    length=strlen(str);
    for(i=0;i<length;i++)
       {
       	  if(str[i]==ch)
       	     {
       	     	for(j=i;j<length;j++)
  	   	        str[j]=str[j+1];
       	     	break;
			 }
	   }
	if(i==length)
	    printf("given character is not present.");
    else
        printf("After deletion  = %s\n",str);
    return 0;
  }

No comments:

Post a Comment