+ 1

Array in c programming

The given code declares an array, that corresponds to game results of a basketball team. 1 represents a win, while 0 represents a loss. The team has played a total of 28 games. Task: Create a program that calculates and outputs the number of win for the given team.

3rd Oct 2024, 1:48 AM
Prakash Kumar Jaiswal
Prakash Kumar Jaiswal - avatar
4 ответов
+ 1
#include <stdio.h> int main() { int results[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1}; int count=0; for(int i=0; i<28; i++){ if(results[i]==1){ count++; } } printf("%d",count); return 0; }
3rd Oct 2024, 3:02 AM
Prakash Kumar Jaiswal
Prakash Kumar Jaiswal - avatar
+ 1
Prakash Kumar Jaiswal , your code is working properly according the task description. i can not see any question either. what is the purpose of this post? `q&a` forum is for coding related questions or discussions. if you are just going to present your code here, this is not the rigth place.
3rd Oct 2024, 11:56 AM
Lothar
Lothar - avatar
0
Sorry I just recently reached out to the solution of this problem. But if you have any other ways to solve this problem in c programming, please solve it. I want to see various aspects to solve this problem!
3rd Oct 2024, 12:14 PM
Prakash Kumar Jaiswal
Prakash Kumar Jaiswal - avatar
0
Your solution is fine as it is. In many cases, there are more than one way to do things. Some techniques require more CPU time or memory than other techniques for a given problem. Your solution is efficient. You could have written it in other ways that are less efficient, but you did not. This is great.
3rd Oct 2024, 2:36 PM
Jerry Hobby
Jerry Hobby - avatar