Saturday, March 31, 2012

Sum of First and Last Digits of a Number

No comments

 /*Sum of First and Last Digit of a Number*/


#include<stdio.h>
#include<conio.h>
     void main()
       {
 int num,sum=0,a,b;

 printf("\n Sum of First and Last Digit of a four Digits Number");

 printf("\n Enter A Number    ::");
 scanf("%d",&num);


 a=num%10;
 b=num/1000; 
 sum=a+b;

 printf("\n First Number is  :: %d",b);
 printf("\n Last Number is   :: %d",a);
 printf("\n Sum : %d",sum);

 printf("\n Want More Need Example for Practice ");
 printf("\n     Logon www.Code2Create.com");

 getch();
}

If you want to add first and last digit number then  
b=num/n 
  • For 2 digits Number  (n=10)
  • For 3 digits Number  (n=100)
  • For 4 digits  Number (n=1000)


0 comments:

Post a Comment

Entries RSS Comments RSS

Sample Text

Pages


Copyright © Lovely Codes
Powered by Blogger
Distributed By Free Blogger Templates | Design by N.Design Studio
Blogger Theme by Lasantha - PremiumBloggerTemplates.com