#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

write the function int countchtr(char string[],int ch);which returns the number of timesthe character ch appears in the string. for example the call countchtr("she lives in Newyork",'e') would return 3.

6 Answers  


Q.1 write aprogram to stack using linklist o insert 40 items? Q.2 write a program to implement circular queue with help of linklist?

0 Answers   TCS,


What is the difference between null pointer and the void pointer?

3 Answers  


How can I increase the allowable number of simultaneously open files?

1 Answers   ABC,


why do some people write if(0 == x) instead of if(x == 0)?

0 Answers  






Is c dynamically typed?

0 Answers  


how many header file is in C language ?

44 Answers   College School Exams Tests, CTS, IBM, IMS, Infosys, ME, Sign Solutions, Wipro, XVT,


Explain is it valid to address one element beyond the end of an array?

0 Answers  


how to print "hai" in c?

13 Answers   TCS,


Is it possible to have a function as a parameter in another function?

0 Answers  


IS it possible to define a zero sized array in c.if it is possible how can the elements of that array can be accessed.array index starts from zero,if it is possible to define zero sized array how can be its first element can be accesseed.

5 Answers   TCS,


Which header file is used for clrscr?

0 Answers  


Categories