Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

c - Can you give me some suggestions on my problem?

I want to solve the problem. The problem is to check whether the number is palindrome or not. There has been a lot of solutions that exist online. But I am trying to solve this problem through my approach without seeing any solution from the internet. I am trying this way->

#include <stdio.h>
int main(){
//Declaring variables for further proceed
int number,reminder,quotient=1;

//Just take the input from the user
printf("Input : ");
scanf("%d",&number);

while(quotient!=0){
    quotient=number/10;
    reminder=number%10;
    printf("%d",reminder);
    number=quotient;

  }



   return 0;
 }

The problem is : My code is work for displaying the reverse order of any given number. But I could not check with this reverse order with the given number. If you can then you are most welcome. Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
//Write a program to check the number whether it is palindrome or not

#include <stdio.h>
int
main(void){

//Put variables for the further proceed
int number, quotient=1, remainder,i=0;

//To declare a character array
char text[100];

//To show the message to the user
printf("Enter an integer number :");

//Taking input from the user
scanf("%d",&number);

//For finding escape the integer number in the reverse order specifically
int number_update=number;

//To find out the integer number in the reverse order
  while(quotient!=0){
  quotient=number_update/10;
  remainder=number_update%10;
  number_update=quotient;
  text[i] = remainder + '0';//Converts integer to character and store to the array
  i++;
  }
 //Converts the string to a whole integer
  int result_of_reverse=atoi(text);

  //Check the result of reverse order with the given integer number
  if(result_of_reverse==number){

    //To display the result
    printf("This is a palindrome number");
  }
  else{

    //To display the result
    printf("This is not a palindrome number");
  }

}

Eventually, I have solve my problem. Thank you all for your suggestions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...