#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 |
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.
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?
What is the difference between null pointer and the void pointer?
How can I increase the allowable number of simultaneously open files?
why do some people write if(0 == x) instead of if(x == 0)?
Is c dynamically typed?
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?
how to print "hai" in c?
Is it possible to have a function as a parameter in another function?
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.
Which header file is used for clrscr?