Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- char x[5],y[5],str[110];
- void value(int length)
- {
- int i,j,a,b,res;
- for(i=0;i<length;i++){
- if(str[i]=='+'){
- a=str[i-1]-'0';
- b=str[i+1]-'0';
- res=a+b;
- printf("%d\n",res);
- return;
- }
- if(str[i]=='-'){
- a=str[i-1]-'0';
- b=str[i+1]-'0';
- res=a-b;
- printf("%d\n",res);
- return;
- }
- if(str[i]=='*'){
- a=str[i-1]-'0';
- b=str[i+1]-'0';
- res=a*b;
- printf("%d\n",res);
- return;
- }
- if(str[i]=='/'){
- a=str[i-1]-'0';
- b=str[i+1]-'0';
- res=a/b;
- printf("%d\n",res);
- return;
- }
- if(str[i]=='^'){
- a=str[i-1]-'0';
- b=str[i+1]-'0';
- res=1;
- for(j=1;j<=b;j++){
- res*=a;
- }
- printf("%d\n",res);
- return;
- }
- }
- }
- int main()
- {
- int i,length;
- gets(str);
- length=strlen(str);
- printf("Letter to change : ");
- scanf("%s",&x);
- printf("New letter : ");
- scanf("%s",&y);
- for(i=0;i<length;i++){
- if(x[0]==str[i]){
- str[i]=y[0];
- }
- }
- if(y[0]>='0'&&y[0]<='9'){
- value(length);
- }
- else{
- printf("%s\n",str);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement