i really need help with this
-
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c
-
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c
-
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c
Is it a homework?
-
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c
Member 14203327 wrote:
Please help me...
What do you have so far? Around these parts, posted code usually results in critiqued code.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c
[https://www.quora.com/Difference-between-while-loops-and-for-loops-in-c-programming-language\](https://www.quora.com/Difference-between-while-loops-and-for-loops-in-c-programming-language)
"(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal
-
Member 14203327 wrote:
Please help me...
What do you have so far? Around these parts, posted code usually results in critiqued code.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
this is the code that i had but when i run it, it gives me a 0(zero) as the answer #include //program for finding the lowest value in an array using a for loop int main (){ int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]
-
this is the code that i had but when i run it, it gives me a 0(zero) as the answer #include //program for finding the lowest value in an array using a for loop int main (){ int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]
Member 14203327 wrote:
int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]<marks[b];b++;){
Let's a look at your
for
loop. In C the for loop is defined asfor( init; condition; increment)
. Whereinit
is the initial condition of the loop,condition
is the end loop condition - that is if the condition expression returns true false, or non-zero, andincrement
is an expression that defines the next step of the loop. Lets look at your for loop:**init** : marks[a] < marks[b]
that's effectively a No-Op, it does evaluate to true, but it does not define the starting condition of the loop**condition** : b++
I expect you know that in C false is zero and true is any non-zero value. Therefore this expression says return the value of b (= 1), then increment b, so now b = 2. At this point, the end-condition of the loop is 1, or true. that means that that the body of the loop (the portion between{
and}
never gets executed.. b will continue to be incremented until it gets to INT_MAX (2147483647), at which point it will roll over to INT_MIN (-2147483646) and continue incrementing until it reaches zero. However, once the value of b reaches 5 then the expressionlower = marks[a]
we get the dreaded undefined behavior, which, if the computer sets itself on fire, is perfectly acceptable, according to the C standard.increment:
empty expression - no action performed. That's not necessarily wrong, there's plenty of times that you might write afor
loop without a increment expression. This is not one of those times. Here's a template for what you should do for your for loop - I'll assume that you do not have C99 or C11, so you need to declare your loop variables outside the for loop:int a; /* index into the marks array \*/
int lowest = marks[0] /* initialize the lowest variable \*/
for( /* initial: we already know that lowest is set to marks[0], so maybe we should set our loop variable to the next index in the array \*/ your code here;
/* condition: We need to iterate over the entire array, so the condition will be when the loop variable a no longer points to a valid array member. The ar -
this is the code that i had but when i run it, it gives me a 0(zero) as the answer #include //program for finding the lowest value in an array using a for loop int main (){ int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]
Member 14203327 wrote:
for (marks[a]<marks[b];b++;){
Among other things, this may be part of your problem. A
for()
loop has three components: initialization, condition, increment. Any of them can be optional. In the initialization section, you have a condition. In the condition section, you have an increment. A more straight-forward approach might look something like:initialize lowest to some arbitrary high number (or assign it to the 1st number in marks, and then just loop 4 times)
loop 5 times
if the current number is less than lowest, re-assign lowest to it
repeat
print"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Please help me with the solutions for this questions, am a beginner in C and am still learning the ropes of c programming: 1.write a method that accepts an array of integers as its parameter and returns the largest value. 2.given the enum below, write a method that accepts Gender as a parameter and returns the string "Sports" for male, "reading" for female. Otherwise return "acting". 3.Given the following marks results int [] marks = {23,14,32,15,17,35,19,12,21}; -write a for loop that will find the lowest mark -write a while loop that will find the lowest marks -write a do....while loop that will find the highest marks the programming language to be used is c
After you figure out how to set-up the for () loop , add some debugging "scaffolding" in few places to see what your code is actually doing in each iteration of the (for) loop. Perhaps adding some basic comments would also help. Leaving variables intentionally uninitialized ( lowest ) is bad habit to get into, it will bite you when things get more complex. Happy learning.
//program for finding the lowest value in an array using a for loop
#define DEBUG
int main (){
int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ;
for (marks[a] -
Member 14203327 wrote:
int marks [] = {20,30,40,50,60}, a = 0, b = 1 , lowest ; for (marks[a]<marks[b];b++;){
Let's a look at your
for
loop. In C the for loop is defined asfor( init; condition; increment)
. Whereinit
is the initial condition of the loop,condition
is the end loop condition - that is if the condition expression returns true false, or non-zero, andincrement
is an expression that defines the next step of the loop. Lets look at your for loop:**init** : marks[a] < marks[b]
that's effectively a No-Op, it does evaluate to true, but it does not define the starting condition of the loop**condition** : b++
I expect you know that in C false is zero and true is any non-zero value. Therefore this expression says return the value of b (= 1), then increment b, so now b = 2. At this point, the end-condition of the loop is 1, or true. that means that that the body of the loop (the portion between{
and}
never gets executed.. b will continue to be incremented until it gets to INT_MAX (2147483647), at which point it will roll over to INT_MIN (-2147483646) and continue incrementing until it reaches zero. However, once the value of b reaches 5 then the expressionlower = marks[a]
we get the dreaded undefined behavior, which, if the computer sets itself on fire, is perfectly acceptable, according to the C standard.increment:
empty expression - no action performed. That's not necessarily wrong, there's plenty of times that you might write afor
loop without a increment expression. This is not one of those times. Here's a template for what you should do for your for loop - I'll assume that you do not have C99 or C11, so you need to declare your loop variables outside the for loop:int a; /* index into the marks array \*/
int lowest = marks[0] /* initialize the lowest variable \*/
for( /* initial: we already know that lowest is set to marks[0], so maybe we should set our loop variable to the next index in the array \*/ your code here;
/* condition: We need to iterate over the entire array, so the condition will be when the loop variable a no longer points to a valid array member. The arthank you, it helped me to write the program properly
-
Is it a homework?
it was a cat