#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?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sight
You just remove the & in the last scanf statement
But also this loop will continue going on(infinite) b'coz
here no ending point.....
BTW if u remove those & it will definatly wait for entering
a charecter....
Is This Answer Correct ? | 4 Yes | 1 No |
c programming of binary addition of two binary numbers
What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;
How to find a missed value, if you want to store 100 values in a 99 sized array?
What is the concatenation operator?
what is data structure?
what is computer engg
Explain what is the difference between functions abs() and fabs()?
write a method for an array in which it can display the largest n next largest value.
Discuss similarities and differences of Multiprogramming OS and multiprocessing OS?
Where are the auto variables stored?
How can I recover the file name given an open stream?
What are the different types of data structures in c?