#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
char another='y';
int num;
for(;another=='y';)
{
printf("Enter a number");
scanf("%d",&num);
printf("squre of %d is %d",num,num*num);
printf("\nwant to enter another number y/n");
scanf("%c",&another);
}
getch();
}
the above code runs only one time.on entering 'y' the
screen disappeares.what can i do?
Answer Posted / shahid sayyad
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
char another='y';
int num;
for(;another=='y';)
{
printf("Enter a number");
scanf("%d",&num);
printf("squre of %d is %d",num,num*num);
printf("\nwant to enter another number y/n");
fflush();
scanf("%c",&another);
}
getch();
}
if you enter any key it act as char and store in
"another",so before scanning we have to flush all the keys
hence fflush is used.
| Is This Answer Correct ? | 4 Yes | 0 No |
Post New Answer View All Answers
Differentiate call by value and call by reference?
Disadvantages of C language.
please explain clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code
Explain what is the most efficient way to store flag values?
What is printf () in c?
Why enum is used in c?
What is identifiers in c with examples?
Explain can the sizeof operator be used to tell the size of an array passed to a function?
State the difference between x3 and x[3].
Why c is a procedural language?
Can you return null in c?
How do I copy files?
What does the function toupper() do?
What are types of preprocessor in c?
struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer