Question #14001

Write program to enter a five digit no..like 12934 n to get 24045 as o/p without arrays

Expert's answer

#include "stdafx.h"

#include<stdio.h>

#include<conio.h>

int main()

{

int n,d1,d2,d3,d4,d5,nd1,nd2,nd3,nd4,nd5;

printf("Please, enter a five digit no:

");

scanf("%d",&n);

d5=n;n=n/10;

d4=n;n=n/10;

d3=n;n=n/10;

d2=n;n=n/10;

d1=n;

nd5=d5+1;

if(nd5>=10){

nd5=0;

nd4=d4+2;

}else{

nd4=d4+1;

}

if(nd4>=10){

nd4=0;

nd3=d3+2;

}else{

nd3=d3+1;

}

if(nd3>=10){

nd3=0;

nd2=d2+2;

}else{

nd2=d2+1;

}

if(nd2>=10){

nd2=0;

nd1=d1+2;

}else{

nd1=d1+1;

}

printf("Output: %d%d%d%d%d",nd1,nd2,nd3,nd4,nd5);

getch();

return 0;

}

#include<stdio.h>

#include<conio.h>

int main()

{

int n,d1,d2,d3,d4,d5,nd1,nd2,nd3,nd4,nd5;

printf("Please, enter a five digit no:

");

scanf("%d",&n);

d5=n;n=n/10;

d4=n;n=n/10;

d3=n;n=n/10;

d2=n;n=n/10;

d1=n;

nd5=d5+1;

if(nd5>=10){

nd5=0;

nd4=d4+2;

}else{

nd4=d4+1;

}

if(nd4>=10){

nd4=0;

nd3=d3+2;

}else{

nd3=d3+1;

}

if(nd3>=10){

nd3=0;

nd2=d2+2;

}else{

nd2=d2+1;

}

if(nd2>=10){

nd2=0;

nd1=d1+2;

}else{

nd1=d1+1;

}

printf("Output: %d%d%d%d%d",nd1,nd2,nd3,nd4,nd5);

getch();

return 0;

}

## Comments

## Leave a comment