#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 conditional operators in C?
What are types of structure?
What are 'near' and 'far' pointers?
What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.
Can one function call another?
What’s the special use of UNIONS?
Write a program to print ASCII code for a given digit.
What is the code for 3 questions and answer check in VisualBasic.Net?
What are keywords in c with examples?
hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel
What is c++ used for today?
c language interview questions & answer
How can I make sure that my program is the only one accessing a file?
a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above
What is assert and when would I use it?