Question #18324

write a program that accepts a list of numbers from a user until a number is repeated. the program then prints out the number of numbers entered(excluding the last and their sum). e.g numbers 5,-6,0,45,45. four numbers entered and their sum is 44

Expert's answer

#include <stdio.h>

#include <iostream.h>

void main(){

int i=0, k, sum=0, check=1, a[100];

while (check){

& cout<<"enter a number: ";

& cin>>a[i];

& if ((i!=1)&&(a[i-1]==a[i])) check=0;

& i++;

}

for (k=0;k<i-1;k++) sum+=a[k];

cout<<i-1<<" numbers entered\n"<<"their sum is "<<sum<<"\n";

}

#include <iostream.h>

void main(){

int i=0, k, sum=0, check=1, a[100];

while (check){

& cout<<"enter a number: ";

& cin>>a[i];

& if ((i!=1)&&(a[i-1]==a[i])) check=0;

& i++;

}

for (k=0;k<i-1;k++) sum+=a[k];

cout<<i-1<<" numbers entered\n"<<"their sum is "<<sum<<"\n";

}

## Comments

## Leave a comment