#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
What is || operator and how does it function in a program?
What is "Hungarian Notation"?
What is meant by recursion?
Write a Program to accept different goods with the number, price and date of purchase and display them
What is the use of bit field?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
What is main function in c?
How can I run c program?
What is the use of clrscr?
What is scanf_s in c?
Explain the use of 'auto' keyword in c programming?
Is that possible to store 32768 in an int data type variable?
Can we increase size of array in c?
Explain what is a static function?
What is structure and union in c?