#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 how do you declare an array that will hold more than 64kb of data?
Explain what is meant by high-order and low-order bytes?
Write a C program where input is: "My name is xyz". output is: "xyz is name My".
When can you use a pointer with a function?
What is a c token and types of c tokens?
a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list
What is the general form of #line preprocessor?
Read N characters in to an array . Use functions to do all problems and pass the address of array to function. 1. Print only the alphabets . If in upper case print in lower case vice versa.
Explain what happens if you free a pointer twice?
What is the most efficient way to count the number of bits which are set in an integer?
What is a stream water?
How can I discover how many arguments a function was actually called with?