Question 1:
#include<stdio.h>
int find_odd(int k)
{
int num;
int counter = 0;
int check = 0;
while(num != -1)
{
scanf("%d",&num);
if(num%2!=0)
{
counter++;
if(counter == k)
{
printf("%d",num);
check = 1;
}
}
}
if((counter != k) && (check == 0))
printf("-1");
return 0;
}
int main()
{
int k;
scanf("%d",&k);
find_odd(k);
return 0;
}
Question 2:
#include<stdio.h>
int main()
{
float num1,num2;
float m_avg;
scanf("%f",&num1);
while(num1 != -1)
{
num2 = num1;
scanf("%f",&num1);
if(num1!=-1)
{ m_avg = (num1+num2)/2;
printf("%0.1f ",m_avg);
}
}
return 0;
}
Question 3:
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int fac = 1;
for(int i = 1; i<n; i++)
{
fac = fac*i;
if(fac <= n)
{
printf("%d ",fac);
}
else
break;
}
return 0;
}
thanks!!
ReplyDelete