C 语言查找数字最后一位的程序

如何编写 C 语言查找数字最后一位的程序并附带示例?.

C 语言查找数字最后一位的程序

此程序将允许用户输入任何数字。然后,它将找到用户输入值的最后一位数字。

/* C Program to Find Last Digit Of a Number */
 
#include <stdio.h>
 
int main()
{
  	int Number, LastDigit;
 
  	printf("\n Please Enter any Number that you wish  : ");
  	scanf("%d", & Number);
  	
  	LastDigit = Number % 10;
  
  	printf(" \n The Last Digit of a Given Number %d =  %d", Number, LastDigit);
 
  	return 0;
}
C Program to Find Last Digit Of a Number 1

C 语言查找数字最后一位的函数程序

这个用于查找数字最后一位的C 语言程序与上面的程序相同。但这次我们使用了 C 语言编程中的函数概念来划分代码。

/* C Program to Find Last Digit Of a Number using Function */
 
#include <stdio.h>

int Last_Digit(int num); 

int main()
{
  	int Number, LastDigit;
 
  	printf("\n Please Enter any Number that you wish  : ");
  	scanf("%d", & Number);
  	
  	LastDigit = Last_Digit(Number);
  
  	printf(" \n The Last Digit of a Given Number %d =  %d", Number, LastDigit);
 
  	return 0;
}

int Last_Digit(int num)
{
	return num % 10;
}
 Please Enter any Number that you wish  : 12457325
 
 The Last Digit of a Given Number 12457325 =  5

评论已关闭。