Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
528 B
6
Indexable
Never
#include <stdio.h>

void main(){
	//break statement
	//user will enter number and as soon as he enters a negative number, the summ of all number before negative comes
	//while loop
	
	int i, j, store, sum;
	printf("How many number you will enter: ");
	scanf("%d", &store);
	
	if(store>0){
		i=1;
		while(i<=store){
			printf("Enter number: ");
			scanf("%d \n", &j);
			if(j<0){
				break;
			}
			sum = sum + j;
			++i;
		}
		printf("The sum is %d", sum);
	}else{
		printf("Enter a valid input");
	}
}