C porgram to find first and last number print using for loop
C Porgram to find first and last number print using for loop :
Write a C program to input a number from user and find first and last digit of number using loop. How to find first and last digit of a number in C programming. Logic to find first and last digit of a given number without using loop in C program
Example :
Input :
1235
Output:
first number : 1
last number : 5
sum of first and last number = 6
Code :
#include<stdio.h>
int main()
{
int n;
int flsum;
printf("Enter the number :");
scanf("%d",&n);
int fast,i;
int last=n%10;
for(i=0;n!=0;i++){
fast=n%10;
n=n/10;
}
flsum=fast+last;
printf("fast number = %d\n",fast);
printf("last number = %d\n",last);
printf("sum of first and last number = %d\n",flsum);
return 0;
}
Write a C program to input a number from user and find first and last digit of number using loop. How to find first and last digit of a number in C programming. Logic to find first and last digit of a given number without using loop in C program
Example :
Input :
1235
Output:
first number : 1
last number : 5
sum of first and last number = 6
Logic to find last digit of a number:
Suppose if n = 12345
then last number is n%10
= > last number = 5
#include<stdio.h>
int main()
{
int n;
int flsum;
printf("Enter the number :");
scanf("%d",&n);
int fast,i;
int last=n%10;
for(i=0;n!=0;i++){
fast=n%10;
n=n/10;
}
flsum=fast+last;
printf("fast number = %d\n",fast);
printf("last number = %d\n",last);
printf("sum of first and last number = %d\n",flsum);
return 0;
}
Output :

No comments