Top |
|
Top |
|
Stack Data Structure
Top |
|
Top |
|
Stack Data Structure
#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; }
#include<iostream> #include<string.h> #include<iomanip> using namespace std; int HexaToDec(char *ch) { int i,base=1,temp,dec=0; i=strlen(ch)-1; while(i>=0) { if(ch[i]>='A'&&ch[i]<='F') temp=int(ch[i])-55; else temp=int(ch[i])-48; dec+=temp*base; base*=16; i--; } return (dec); } int main() { char ch[3]="1A"; cout<<"Enter a Hexadecimal number:-"; char hexa[100]; cin>>hexa; cout<<endl<<HexaToDec(hexa); return 0; }