#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

c programming of binary addition of two binary numbers

4 Answers  


What is the value of y in the following code? x=7;y=0; if(x=6) y=7; else y=1;

12 Answers   TCS,


How to find a missed value, if you want to store 100 values in a 99 sized array?

0 Answers   Honeywell, Zomato,


What is the concatenation operator?

0 Answers  


what is data structure?

5 Answers   CBSE,






what is computer engg

1 Answers  


Explain what is the difference between functions abs() and fabs()?

0 Answers  


write a method for an array in which it can display the largest n next largest value.

1 Answers   Value Labs,


Discuss similarities and differences of Multiprogramming OS and multiprocessing OS?

4 Answers   TCS,


Where are the auto variables stored?

0 Answers   TISL,


How can I recover the file name given an open stream?

0 Answers  


What are the different types of data structures in c?

0 Answers  


Categories