+ 2
In this code everything right or not , i mean array count and iteration count . And how i is connected with array ?
4 Réponses
+ 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 ;
}
+ 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.
+ 2
Jayakrishna🇮🇳 thanks sir
0
You're welcome.. Abhay mishra