# C programming Homework

+1 vote

use ONLY “stdio.h” library

Write two functions in a single program. After writing following functions, call them from main function to test if they are working correctly (how functions will be tested depends on programmer).

i) Write a function that will receive two integer variables (x,y) as parameter. This function will find and show on screen all odd numbers between x and y (both included and order of x and y, while sending them to defined function, is not important).

ii) Write a function that will perform following mathematical expression (note that, x, y and z are integer values), and return result.

answered May 10 by (280 points)
```#include<stdio.h>
int x, y, z;
int main(){
scanf(x);
scanf(y);
if(x>y)
return;
for(z=x;z<y;z++)
{
if(z%2!=0)
printf(z);
}
return 0;
}
//I did not meet all the requirements (I used only one function) but I hope I am helpful. Here is a separate example with the second function:
int soli (int a);
{
int b;
b = a + 1;
return b;
} ```
commented May 10 by (280 points)
is it correct?
answered May 10 by (5,280 points)
#include <stdio.h>

void oddNumbers(int a, int b){

printf("**oddNumbers function**\n");
printf("Odd numbers between %d and %d are: ", a, b);

if (a < b){

for(int counter = a; counter <= b; counter++){
if(counter % 2 != 0)
{
printf("%d ", counter);
}
}
}
else{

for(int counter = b; counter <= a; counter++){
if(counter % 2 != 0){
printf("%d ", counter);
}
}
}

}

int mathematicalExpression(int a, int b){

printf("**mathematicalExpression function**\n");

char operator;

printf("Please enter an operator (+, -, * or /): ");
//operator = getchar();
scanf(" %c", &operator);

switch(operator)
{
case '+':
return ("%d", a + b);
break;
case '-':
return ("%d", a - b);
break;
case '*':
return("%d", a * b);
break;
case '/':
return("%d", a / b);
break;
default:
printf ("Error! operator is not correct");
}
}

int main(){

int x, y;