Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

c program to obtain the sum of first and last digit of no. first line contains T, total number of test cases. Then lines containing int N?

my code is not working.. i have given my code as an answer and also as screenshot.. plz help

Attachment image

2 Answers

Relevance
  • 3 years ago
    Favorite Answer

    x = N % 10 // gives the last digit.

    while (N / 10)

    N = N / 10; // this while loop gives the first digit.

    printf ("%d\n", N + x);

  • ?
    Lv 7
    3 years ago

    this works much better

    you do not want to use T--

    You want T/=10;

    read the first

    then keep reading last til T is zero

    the last one read is the last

    #include <stdio.h>

    int main(void){

    int T,f,l;

    T=32346;

    f=T%10;

    T/=10;

    l=T%10;

    while(T){

    l=T%10;

    T/=10;

    }

    printf("sum=%d\n",l+f);

    return 0;

    }

Still have questions? Get your answers by asking now.