// program to add 5 to the value of given floating point number and read and display that number thorugh getchar() and putchar() // compile this program with gcc -lm programname.c becuase it uses math.h library #include #include int main() { char c[20],dc[20],ch; // c store given floating value and dc stores doubled floating value in character format int i,k; int d1,d2,count1=0,count2=0,strl,sign=0; // sign is to stor thew sign of final answer if it is zero positve and if it is 1 negative printf("enter the floating point number"); i=0; while((ch=getchar())!='\n') { c[i++]=ch; } c[i]='\0'; i=0; strl=0; // finding how many numbers are there after decimal point while(c[i]!='.' && c[i]!='\0') { i++; strl++; } strl++; if(c[i]!='\0') { while(c[++i]!='\0') { count1++; strl++; } } // store this input characters as an integer in d1 count2=0; d1=0; if(count1==0) strl--; for(i=strl-1;i>=0;i--) { if(c[i]!= '.' && c[i]!='-') { d1=d1+(c[i]-'0')*pow(10,count2++); } } //add 5 to the value if(c[0]=='-') { d2=-d1+5*pow(10,count1); // to adjust according to decimal point } else d2=d1+5*pow(10,count1); if(d2<0) { sign=1; d2=-d2; } // store the values in array as characters in reverse order strl=0; if(count1!=0) { dc[count1]='.'; strl++; } for(i=0;d2!=0;i++) { if(i!=count1 || count1==0) { strl++; k=d2%10; dc[i]=k+48; d2=d2/10; } } if(sign==1) { //if(dc[i++]!='.') dc[i++]='-'; strl++; } dc[i++]='\0'; putchar('\n'); // display using putchar for(i=strl-1;i>=0;i--) putchar(dc[i]); return 0; }