Can you help fix this error
lvalue required as left operand of assignment
if(isEven(input)=1)
int main()
{
int input;
input == 0;
printf("Please input an integer: ");
scanf("%d", &input);
if(isOdd(input)=1)
{
printf("%d is an odd number!\n", input);
}
if(isEven(input)=1)
{
printf("%d is an even number!\n", input);
}
return 0;
}
The statement that we write inside if must be a statement whose answer can be derived as true or false. Generally conditional statements are used inside if.
lets take few examples here:
1) consider x=1 and y=1
so in order to check whether the value of x and y are equal or not we will write as:
if(x==y) -> here == is used for comparison whose result will be true
2) consider x=2 and y=4
and we need to check whether x is greater than y then we use the following statement
if(x>y) -> since x=2 and y=4, means x is not greater than y so the answer to the statement is false.
_____________________________________________________________________________________________
In your program:
if(isEven(input)=1)
The above statement is using = means that assign 1 to the the function isEven. These statement is incorrect as we cannot assign a number to a function and if needs the result as true or false which requires comparison.
That is why you are getting the lvalue required error.
so instead of if(isEven(input)=1)
we have to use if(isEven(input)==1)
and instead of if(isOdd(input)=1)
we have to use if(isOdd(input)==1)
____________________________________________________________________________________________
I have executed the program for you so please check the program:
#include<stdio.h>
int isEven(int input)
// isEven() to check whether
the number is even or not
{
if(input%2==0)
// if
number modulus 2 is equals to 0 then return 1 else return 0
return 1;
else
return 0;
}
int isOdd(int input)
// isOdd() to check whether
the number is odd or not
{
if(input%2==1)
// if
number modulus 2 is equals to 1 then return 1 else return 0
return 1;
else
return 0;
}
int main()
{
int input;
input == 0;
printf("Please input an integer: ");
// take the number from user
in input variable
scanf("%d", &input);
if(isOdd(input)==1)
// call
isOdd() and if return value is 1 then print that the number is
odd
{
printf("%d is an odd number!\n", input);
}
if(isEven(input)==1)
// call isEven() and if the
return value is 1 then print the number is even
{
printf("%d is an even number!\n", input);
}
return 0;
}
==========================================================================================
Output:

Can you help fix this error lvalue required as left operand of assignment if(isEven(input)=1) int main()...
Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() { int number; scanf("%d", &number); if (number % 2 == 0) { printf("Even\n"); } else { printf("Odd\n"); } return 0; }
Fix the code. Use Valgrind to compile below code with no warning and no memory error. Also give a comment about how you fix the code. gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 $* -o question5 question5.c && ./question5 gcc -std=c99 -pedantic -Wall -Wextra -ftrapv -ggdb3 -fsanitize=address -o question5 question5.c && ./question5 Both of these should get the same output . For example if we input 65535 4 3 2 1 it should give us a output with What is...
Whats wrong with my code? Please help! #include <stdio.h> int main() { //variables int m1, m2, m3; int a1, a2, a3; int f1, f2, f3; //input acceleration printf("Enter value for a1: "); printf("Enter value for a2: "); printf("Enter value for a3: "); scanf("%d %d %d",&a1,&a2,&a3); //input mass printf("Enter value for m1: "); printf("Enter value for m2: "); printf("Enter value for m3: "); scanf("%d %d %d",&m1,&m2,&m3); //functions f1=m1*a1; m1=f1/a1; a1=f1/m1; f2=m2*a2; m2=f2/a2; a2=f2/m2; f3=m3*a3; m3=f3/a3; a3=f3/m3; //command: printf("f1=%d\n, m1=%d\n, a1=%d\n"); printf("f2=%d\n,...
Hi, I'm trying to write C code that will print the odd abundant numbers between 1 and 5000 and I've written a program for it but it doesn't work. If you would be able to help me fix it or point out where I went wrong that would be awesome. # include <stdio.h> int main () { int getSum(int n) int i, n, j, sum = 0; /* print initial statement to give context of program*/ printf("...
i need flowchart for the following c code #include <stdio.h> int main() { int n, i, sum = 0; printf("Enter an integer: "); scanf("%d",&n); i = 1; while ( i <=n ) { sum += i; ++i; } printf("Sum = %d",sum); return 0; }
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
Solve using C programming
3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...
sort.c
#include <stdlib.h>
#include <stdio.h>
#include "libsort.h"
int main()
{
int* array;
int size, c;
float median;
printf("Enter the array size:\n");
scanf("%d", &size);
array = (int*) malloc(size *
sizeof(int));
printf("Enter %d integers:\n", size);
for (c = 0; c < size; c++)
scanf("%d",
&array[c]);
sort(array, size);
printf("Array sorted in ascending
order:\n");
for (c = 0; c < size; c++)
printf("%d ",
array[c]);
printf("\n");
median = find_median(array,...
I have a question on an assignment for C++. I have my code available here and just want someone to look over it using MS VS 2010 express, for that is what my instructor is using. Write a program that mimics a calculator. The program should take as input two integers and the opreation to be performed. It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message.) //**This...
If the code below has an error, circle the line that contains the error. #include <stdio.h> int main (void) { int even[ ] = { 2, 4, 6, 8 } ; int odd[ ] = { 1, 3, 5, 7 }; int *int_ptr; int_ptr = even; odd = int_ptr; printf(ā %i, %i\nā, odd[0], odd[1]); return 0; }