How to Write a program that in a given natural number x insert figure c at position p . The numbers x , c and p are entered from standard input .
For example , x = 140 , c = 2 , p = 2 , the result is the 1420th
Solution:
- #include<stdio.h>
- #include<math.h>
- int main() {
- int x,c,p,i,y,d;
- scanf("%d%d%d", &x,&c,&p);
- printf("Number: %d, figure %d, required position: %d\n", x,c,p);
- i=1;
- y=10;
- if(i==p){
- x=x*10;
- x=x+c;
- printf("X: %d\n", x);
- }
- while(i<p){
- i++;
- c=c*10;
- if(i==p){
- d=x%y;
- x=x-d;
- x=x*y;
- x=x+c+d;
- printf("X: %d\n", x);
- }
- y=10*y;
- }
- return 0;
- }