Hi Pravalika, getch(), accepts users input from the keyboard, a character. Its commonly used to view the until the user enters something and then the program can exit. But its real purpose is to accept and return the character entered by the user. In some compilers, a string can be entered but the only first letter will be returned only.
i should be initialized to 0. only then it will print even numbers.
I have got this initialized to 2 so that it starts printing even numbers from 2. Thanks for your inputs mate 🙂
This code only prints even numbers upto n , not first n even numbers.
Better approach is :
firstnEven1(){
int i,n,t=0;
printf(“\nEnter n:”);
scanf(“%d”,&n);
for(i=1;i<=n;i++){
t+=2;
printf("%4d",t);
}
}
firstnEven2(){
int n,count1=0,i=1;
printf("\nEnter n:");
scanf("%d",&n);
printf("\nFirst %d even numbers:\n",n);
while(count1 < n){
if(i%2 != 0){
printf("%5d",i);
count1++;
}
i++;
}
}
yes correct ! Thank you for sharing your code!
i want meaning of getch in c languge
Hi Pravalika, getch(), accepts users input from the keyboard, a character. Its commonly used to view the until the user enters something and then the program can exit. But its real purpose is to accept and return the character entered by the user. In some compilers, a string can be entered but the only first letter will be returned only.