1. Write a program that uses a for statement to calculate and print the average
ID: 3628651 • Letter: 1
Question
1. Write a program that uses a for statement to calculate and print the average of four integers.2. Write a program that uses a for statement to find the smallest of five integers.
3. Write a program that calculate and print the product of odd integers from 1 to 15.
4. Write a program to find the factorial of 7.
5. Write a program that uses a for statement to sum a sequence of integers. The first input integer specifies the number of values that need to be entered. The program should read only one value per input statement.
Explanation / Answer
please rate - thanks
next time 1 question per post, but these are simple
#include <iostream>
using namespace std;
int main()
{int i,sum=0,n;
double average;
for(i=0;i<4;i++)
{cout<<"Enter number "<<i+1<<": ";
cin>>n;
sum+=n;
}
average=sum/4.;
cout<<"The average is "<<average<<endl;
system("pause");
return 0;
}
---------------------------------
#include <iostream>
using namespace std;
int main()
{int i=0,small,n;
cout<<"Enter number "<<i+1<<": ";
cin>>small;
for(i=1;i<5;i++)
{cout<<"Enter number "<<i+1<<": ";
cin>>n;
if(n<small)
small=n;
}
cout<<"The smallest number is "<<small<<endl;
system("pause");
return 0;
}
-----------------------------------------
#include <iostream>
using namespace std;
int main()
{int i=0,prod=1;
for(i=1;i<=15;i+=2)
{prod*=i;
}
cout<<"The product is "<<prod<<endl;
system("pause");
return 0;
}
------------------------------------------
#include <iostream>
using namespace std;
int main()
{int i=0,nf=1;
for(i=1;i<=7;i++)
{nf*=i;
}
cout<<"7! is "<<nf<<endl;
system("pause");
return 0;
}
--------------------------------
#include <iostream>
using namespace std;
int main()
{int i=0,n,sum=0,num;
cout<<"How many numbers are there? ";
cin>>n;
for(i=1;i<=n;i++)
{cout<<"Enter number "<<i<<": ";
cin>>num;
sum+=num;
}
cout<<"the sum of the "<<n<<" numbers is "<<sum<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.