#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


Please Help Members By Posting Answers For Below Questions

What are predefined functions in c?

818


Write a Program to find whether the given number or string is palindrome.

1031


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?

2233


What is the difference between fread buffer() and fwrite buffer()?

939


What does emoji p mean?

820


Is a pointer a kind of array?

869


List some applications of c programming language?

766


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.?

859


How can I open files mentioned on the command line, and parse option flags?

850


Can you please compare array with pointer?

865


Why do we need arrays in c?

854


Write a program of advanced Fibonacci series.

934


What are unions in c?

808


What are qualifiers in c?

799


Describe the difference between = and == symbols in c programming?

1053