TASK 3: Use different loops to print the odd/negative numbers 1 to 101. All prog
ID: 3678896 • Letter: T
Question
TASK 3: Use different loops to print the odd/negative numbers 1 to 101. All programs will print the same output in the same order. Using a for loop that increments the loop control variable by 2 each iteration Using a for loop whose loop control variable goes from 0 to 50. Using a for loop whose loop control variable goes from 100 down to 0. Using an infinite for loop with no conditional expression and exiting the loop with a break statement Using a while loop Using a do-while loop. There should be 6 different Snipping photos. One photo for each program A - F.Explanation / Answer
Answer 1->
#include <stdio.h>
#include <conio.h>
int main()
{
int i;
for (i=1 ;i<=101 ; i=i+2)
{
Printf(“%d ” , i*(-1));
}
}
Answer 2->
int main()
{
int I;
for (i=1 ;i<=50 ;i=i+2)
{
Printf(“%d ” , i*(-1));
}
for(i=51;i<=101 ;i=i+2)
{
Printf(“%d ” , i*(-1));
}
Answer 3->
Void insertion_sort(int[],int)
int main()
{
int a[101],n,I;
for (i=101; i>0 ; i=i-2)
scanf(“%d ”, &a[i]);
insertion_sort(a,n);
for(i=0; i<=n; i++)
printf(“%d ” ,a[i]);
getch();
}
Void insertion_sort(int a[],int n)
{
Int I,j,temp;
For(i=1 ;i<=n ;i++)
{
temp=a[i];
for( j=i; j>=0 && a[j] > temp ;j--)
a[j+1]=a[j];
a[j+1]=temp;
}
}
Answer 4->
int main()
{
int n, i;
Printf(“ enter any number which is more than 102”);
Scanf(“%d” , n);
For(i=1; i<=n ;i++)
{
If( i%2!=0 && i<0)
If(i== -101)
{
break
}
Scanf(“%d ” ,i);
Return 0;
}
Answer 5->
int main()
{
Int n, i;
i=1;
n=101;
while (i<=n)
{
If(i%2!=0 && i<0)
printf(“%d ”, i);
i++;
}
getch();
}
Answer 6->
int main()
{
int n,i;
i=1;
n=101;
do
printf(“%d ”, i*(-1));
i=i+2;
}
While(i<=n)
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.