New Number by adding 1 to each digit coderinme

New Number by adding 1 to each digit coderinme

New Number by adding 1 to each digit coderinme
To find new number generated by adding 1 to each of its digits of a five digit number entered from keyboard, we codes as follows:

#include<stdio.h>
int main()
{
long int num,temp,sum=0;
printf("\nEnter a 5 digit number : ");
scanf("%ld",&num);
printf("\nThe number after adding 1 to each digit : ");
while( num != 0)
{
temp = num % 10;
temp = temp + 1;
if(temp == 10)
temp = 0;
num = num / 10;
sum = ( sum * 10 ) + temp;
}
num = 0;
while( sum != 0)
{
temp = sum % 10;
sum = sum / 10;
num = ( num * 10 ) + temp;
}
printf("%ld",num);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

New Number by adding 1 to each digit coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.