Blogger templates

Pages

Tuesday, 1 May 2012

C Program: How to Find First and Last digit of a three digit Number

first last getch

Function of getch():
  • getch() is a function included in the <conio.h> header file. 
  • It is used to take input a single character from keaboard. 
  • The input character is not displayed on the screen. 
  • It is used for output screen stopper.
Some shortcuts:
F2 => save
F3 => open
F5 => full screen

alt+F9 => compilation
ctrl+F9 => run the program
alt+x => exit

Input a three digit number and find out its first digit and last digit: 

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;
clrscr();
printf(" Enter value of a:");
scanf("%d" ,&a);
b=a%10;
c=(a/10)/10;
prinf(" Last digit=%d\n" ,b);
prinf(" First digit=%d\n" ,c);
getch();
}

Output:
Enter value of a:
145
Last digit=5
First digit=1 
In the next section we discuss how to calculate middle digit of a three digit number >>>>>>>>>

0 comments:

Post a Comment