#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 are predefined functions in c?
Write a Program to find whether the given number or string is palindrome.
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?
What is the difference between fread buffer() and fwrite buffer()?
What does emoji p mean?
Is a pointer a kind of array?
List some applications of c programming language?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
How can I open files mentioned on the command line, and parse option flags?
Can you please compare array with pointer?
Why do we need arrays in c?
Write a program of advanced Fibonacci series.
What are unions in c?
What are qualifiers in c?
Describe the difference between = and == symbols in c programming?