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
1
Expert's answer
2012-11-13T04:41:00-0500
#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"; }
Comments
Leave a comment