reverse three digit number

C program to find the reverse of three digit number without using any control control structure.

/*reverse three digit number*/

#include <stdio.h>

int main()

{
int num,d;

printf(“Enter three digit number\n”);

scanf(“%d”, &num);

d=num/10;

num=((num%10)*100 + (d%10)*10 + d/10);

printf(“the reverse three digit number is \n%d\n”, num);

return 0;

}

Output
Enter three digit number
432
the reverse three digit number is
234

Enter three digit number
798
the reverse three digit number is
897

C program to sum digits of a number

This post explain how to calculate sum of digits of a 4 digit number without looping.

/* Program to sum digits of number*/
#include<stdio.h>
int main()
{
int num,last_digit,sum=0;
printf(“Enter a 4 digit number\n”);
scanf(“%d”,&num);
last_digit=num%10;
num=num/10;
sum=sum+last_digit;
last_digit=num%10;
num=num/10;
sum=sum+last_digit;
last_digit=num%10;
num=num/10;
sum=sum+last_digit;
sum=sum+num;
printf(“the sum of 4 digit number is %d\n”,sum);
return 0;
}

Output:

Enter a 4 digit number
2345
the sum of 4 digit number is 14