#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



#include<stdio.h> #include<conio.h> void main() {clrscr(); char another='y..

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

#include<stdio.h> #include<conio.h> void main() {clrscr(); char another='y..

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

#include<stdio.h> #include<conio.h> void main() {clrscr(); char another='y..

Answer / jyoti goyal

Just replace %c by %s in the last scanf.

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

Explain how do you declare an array that will hold more than 64kb of data?

0 Answers  


Explain what is meant by high-order and low-order bytes?

0 Answers  


Write a C program where input is: "My name is xyz". output is: "xyz is name My".

1 Answers   TCS,


When can you use a pointer with a function?

0 Answers  


What is a c token and types of c tokens?

0 Answers  


a character or group of characters that defines a register,or a part of storage a) memory b) byte c) address d) linear list

0 Answers  


What is the general form of #line preprocessor?

0 Answers  


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.

1 Answers  


Explain what happens if you free a pointer twice?

0 Answers  


What is the most efficient way to count the number of bits which are set in an integer?

0 Answers  


What is a stream water?

0 Answers  


How can I discover how many arguments a function was actually called with?

0 Answers  


Categories