#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 |
Explain the advantages of using macro in c language?
What are c identifiers?
Is there something we can do in C but not in C++? Declare variable names that are keywords in C++ but not C.
Why is this loop always executing once?
how to print this sereis 2 4 3 6 5..........?
Identify the operators that is not used with pointer a. && b. # c. * d. >>
What is the difference between near, far and huge pointers?
Why pointers are used in c?
what is an inline fuction??
What does the message "warning: macro replacement within a string literal" mean?
What is the difference between mpi and openmp?
Write a program to swap two numbers without using the third variable?