C program to delete the second last digit.
Sample Input 12345, Output 1235
Program:
#include<stdio.h>
int main()
{
int num,temp1,temp2;
printf("enter num: ");
scanf("%d",&num);
temp1=num%10; /* store last digit in temp1 */
num=num/10; /* making number one digit shorter */
temp2=num%10; /* store the second last digit in temp2 */
num=num-temp2+temp1; /* add the last digit and subtract second last digit to shorter number */
printf("%d",num);
return 0;
}
int main()
{
int num,temp1,temp2;
printf("enter num: ");
scanf("%d",&num);
temp1=num%10; /* store last digit in temp1 */
num=num/10; /* making number one digit shorter */
temp2=num%10; /* store the second last digit in temp2 */
num=num-temp2+temp1; /* add the last digit and subtract second last digit to shorter number */
printf("%d",num);
return 0;
}
4 comments:
n = -10
when we use -10
then your program does run...try to modify your code
Stupid
Post a Comment