// program to double 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; 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++); } } //double the value d2=d1*2; // 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(c[0]=='-') { dc[i++]='-'; strl++; } dc[i]='\0'; putchar('\n'); // display using putchar for(i=strl-1;i>=0;i--) putchar(dc[i]); return 0; }