0

Can anyone tell what is the time complexity of this program

#include<stdio.h> Int main() { Int a[10]; Int I, j, nsum=0; For(i =0; i<n; i++) { Scanf("%d",&a[i]); } For(j=0;j<n;j++) { Sum=sum+a[i]; } Printf ("%d",sum); Return 0; }

29th May 2022, 6:56 PM
Sunilsingh Nagarkoti
1 ответ
0
It looks deceptively like O(n), doesn't it, Jay Matthews? But a is limited to 10 entries. So, n, which is undeclared, can at most be 10. Which makes it O(1), else undefined and most likely crashing. But since n and sum are undeclared, and this program thus won't even compile, the complexity is ... what? ... O(0)? I think it is safe to say that the question cannot be answered unless a working program is presented.
30th May 2022, 8:21 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar