+ 2

In this code everything right or not , i mean array count and iteration count . And how i is connected with array ?

https://code.sololearn.com/cXTZf5aj23r7/?ref=app

16th Mar 2022, 12:17 PM
Abhay mishra
Abhay mishra - avatar
4 odpowiedzi
+ 4
#include<stdio.h> int main() { int i , avg , sum=0 ; int marks[3] ; // aray declaration . for(i=0;i<3;i++) { //indexs 0,1,2 are valid only printf("Enter marks = ") ; scanf("%d" , &marks[i]) ; //put &mark[i]] } for(i=0;i<3;i++){ // i<3 index starts from 0 sum = sum + marks[i] ; } avg = sum / 3 ; //avg = sum / no.of elemements printf("Average marks = %d\n" , avg) ; return 0 ; }
16th Mar 2022, 12:26 PM
Jayakrishna 🇮🇳
+ 4
Adding to what was already suggested, you can also increment <sum> by <marks>[ i ] in the first for...loop rather than doing it in a separate for...loop.
16th Mar 2022, 1:09 PM
Ipang
+ 2
16th Mar 2022, 12:48 PM
Abhay mishra
Abhay mishra - avatar
0
You're welcome.. Abhay mishra
16th Mar 2022, 12:53 PM
Jayakrishna 🇮🇳