Friday, June 15, 2012
Transferring Control of a Program Unconditionally
Syntax : goto <identifier>;
keyword transfers the control of a program unconditionally, to the location of a local label specified by <identifier>
Note: The use of goto statement is usually avoided in good programming practice. A program code can be restructured to avoid goto statement. Do not goto a label inside a repetitive structure or a switch statement.
getchar() is a macro that gets a character from stdin. Note that getchar reads from stdin and is line
buffered; ie. it will not return until you press enter.
getch() reads a single character from the keyboard without echoing to the screen.
getche() reads a single character from keyboard and echoes to the screen.
getc() is a macro that gets one character from a stream. It returns the next character on the given input
stream and increments the stream's file pointer point to the next character.
Declaration int getc(FILE a Stream);
gotoxy - Positions cursor in a text window
Syntax : gotoxy(int x, int y) If the co-ordinates are invalid, the call to gotoxy is ignored.
/* Larger number*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int a, b, c, max;
start:
printf(“Enter a number : ");
scanf(“%d”, &a);
printf(“Enter another : ");
scanf(“%d”, &b);
if (a = = b)
{
printf(“\n Please enter two different numbers \n”);
gotoxy(5,20);
printf(“Press any key to continue ...\n”);
getch();
goto start;
}
else if (a>b)
max = a;
else
max = b;
printf(“\n The larger number is %d\n”, max);
}
/* Weather */
# include <stdio.h>
# include <conio.h>
# define max_temp 35
# define min_temp 25
# define max_humi 30
# define min_humi 15
int main()
{
float temp, humi;
printf(“Enter today’s temperature : ”);
scanf(“%f”, &temp);
printf(“Enter humidity : ”);
scanf(“%f”, &humi);
if (temp > max_temp && humi > max_humi)
printf(“\n Today is Hot and humid \n”);
else if (temp > max_temp && humi < min_humi)
printf(“\n Today is Hot and dry \n”);
else if (temp < min_temp && humi > max_humi)
printf(“\n Today is cold and humid \n”);
else if (temp < min_temp && humi < min_humi)
printf(“\n Today is dry and cold \n”);
else if (temp > max_temp || temp <min_temp || humi > max_humi || humi < min_humi)
printf(“\n Weather is not norma l\n”);
else
printf(“\n Weather is normal \n”);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment