lundi 22 mars 2021

why my break statement inside IF is not working?

This is my code I am trying to print the subarray of the given sum why break statement inside if condition is not working, help me with solutions..

#include<stdio.h>
int main(){
    int n,s,i,temp=0;
    scanf("%d",&n);
    scanf("%d",&s);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        for(int j=i;j<n;j++){
       temp=temp+a[j];
       if(temp==s){
         printf("%d %d\n",i+1,j+1);
         break;
       }
    }
    temp=0;
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire