#include<stdio.h>#include<conio.h>
main(){int i=1,n;
clrscr();printf("Enter n : ");scanf("%d",&n);while(i<=n){printf("%d\t",i);
i=i+2;}getch();}

#include<stdio.h>
#include<conio.h>
main()
{
int i=1,n;
clrscr();
printf("Enter n : ");
scanf("%d",&n);
while(i<=n)
{
printf("%d\t",i);
i=i+2;
}
getch();
}

2 thoughts on “028. Write a Program to print first n odd numbers in C language”

Here i should be initilaized to 1.
here i is initialised to 2
let n=10
2<10
print 2
but 2 is not an odd number.
so this should be the case
i=1 initially
n=10
1<10
print 1
1 is an odd number

Here i should be initilaized to 1.

here i is initialised to 2

let n=10

2<10

print 2

but 2 is not an odd number.

so this should be the case

i=1 initially

n=10

1<10

print 1

1 is an odd number

Hi Shivam, thanks for rectifying the mistake. It is corrected now ðŸ™‚

Really appreciate your input.