Logic to Find First and Last Digit

Last Digit:

#include<stdio.h>
int main(){
    int num,lastdigit;
    printf("enter any number:");
    scanf("%d",&num);
    lastdigit=num%10;
    printf("lastdigit = %d",lastdigit);
    return 0;
}

First Digit:

#include<stdio.h>
int main()
{
    int num,first;

    scanf("%d",&num);
    first=num;
    while(first>=10)
    {
        first=first/10;
    }
    printf("%d",first);

    return 0;
}

 

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published.