Practice Program
Solution: through for loop
void main()
{
int n,i;
printf("How many Odd number you want to print: ");
scanf("%d",&n);
printf("Odd numbers are :\n");
for(i=0;i<n;i++)
{
printf("%d\t",(i*2)+1);
}
}
void main() { int n,i; printf("How many Odd number you want to print: "); scanf("%d",&n); printf("Odd numbers are :\n"); for(i=0;i<n;i++) { printf("%d\t",(i*2)+1); } }
Output1
How many Odd number you want to print:5
Odd numbers are :
1 3 5 7 9
Odd numbers are :
1 3 5 7 9
Output2
How many Odd number you want to print:10
Odd numbers are :
1 3 5 7 9 11 13 15 17 19
Odd numbers are :
1 3 5 7 9 11 13 15 17 19
Output3
How many Odd number you want to print: 15
Odd numbers are :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
Odd numbers are :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
Solution : through while loop
void main()
{
int n,i = 0;
printf("How many Odd number you want to print: ");
scanf("%d",&n);
printf("Odd numbers are :\n");
while(i<n)
{
printf("%d\t",(i*2)+1);
i++;
}
}
void main() { int n,i = 0; printf("How many Odd number you want to print: "); scanf("%d",&n); printf("Odd numbers are :\n"); while(i<n) { printf("%d\t",(i*2)+1); i++; } }
Solution: from do-while loop>
void main()
{
int n,i = 0;
printf("How many Odd number you want to print: ");
scanf("%d",&n);
printf("Odd numbers are :\n");
do
{
printf("%d\t",(i*2)+1);
i++;
} while(i<n);
}
void main() { int n,i = 0; printf("How many Odd number you want to print: "); scanf("%d",&n); printf("Odd numbers are :\n"); do { printf("%d\t",(i*2)+1); i++; } while(i<n); }
0 Comments
Post a Comment