plz tell me the coding of this question

–2 votes
asked Nov 19, 2017 by Fizza Sajjad (310 points)
Q:Write a C function to receive an integer of 3 digits then calculates and returns the sum of the MSD and the LSD. For example if your function received 345 it should return 8 ?

4 Answers

0 votes
answered Nov 20, 2017 by Tomberry64
You can use the following function

unsigned int SumOfFirstAndThirdDigit(unsigned int Num)
{
    if(Num > 999) Num = 999;
   
    return ((Num / 100) + (Num % 10));
}
+2 votes
answered Nov 20, 2017 by sai yaddalapudi (300 points)
#include <stdio.h>

int main()
{
    printf("Enter a three digit number\t");
    int n;
    scanf("%d",&n);
    if(n>=101 && n<=999)
    {
        printf("%d",(n/100)+(n%10));
    }
    else
    {
        printf("Enter a valid three digit number");
    }

    return 0;
}
commented Nov 24, 2017 by ganji kalyani
y dont u take  100 in if condition
commented Nov 24, 2017 by ganji kalyani
#include <stdio.h>
#include<math.h>
int main(int argc,char* argv[])
{
    int n=atoi(argv[1]);
    int s,a=0,r,p,k;
    k=n;
    while(n>0)
    {
        r=n%10;
        n=n/10;
        a++;
    }
    p=a-1;
    s=(k/pow(10,p))+(k%10);
    printf("%d",s);
    
}//this code is efficient for any number
commented Dec 5, 2017 by Akshat Dodwad (230 points)
Exactly because 100 is also a three digit number
0 votes
answered Nov 15, 2018 by anonymous
#include<stdio.h>

int main(){

int sum=0,a,b,n,d,raj,nick;

scanf("%d",&n);

nick=n;

while(n>0){

raj=n%10;

sum=raj+sum*10;

n=n/10;

}

a=nick%10;

b=sum%10;

d=a+b;

printf("%d",d);

return0;

}
0 votes
answered Nov 19, 2018 by MohammedRamzan (140 points)
int digits_sum(int num) {

if(num>99 && num<1000) {

return ((num%10) + (num/100));

}

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...