using C++
1) write a program to calculate to avg of N number of subjects.
2)write a program to find the factorial of 5!
5*4*3*2*1
3)write a program to display the multiplication table for any number
please enter number : 3
1*3=3
2*3=6
2*4=
10*3=30
4) find the factorial on n
1.program to calculate to avg of N number of subjects.
#include <iostream>
using namespace std;
int main()
{
int N;
double k,sum=0;
cin>>N;
for(int i=0;i<N;i++)
{
cin>>k;
sum=sum+k; /* to add the score of total subjects*/
}
double Avg=sum/N;/* average of subjects*/
cout<<Avg;
return 0;
}
2.program to find the factorial of 5!
#include <iostream>
using namespace std;
int main()
{
int sum=1;
for(int i=1;i<=5;i++)
{
sum=sum*i;
}
cout<<sum;
}
3. program to display the multiplication table for any number
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n; /*taking input of a number*/
for(int i=1;i<=10;i++)
{
cout<<i<<" *"<<n<<" =
"<<i*n<<"\n"; /* table of the number taken in
input*/
}
return 0;
}
4. program to print factorial of n
#include <iostream>
using namespace std;
int main()
{
int n,sum=1;
cin>>n;
for(int i=1;i<=n;i++)
{
sum=sum*i;// multiplying all the numbers from 1 to n and storing it
in sum
}
cout<<sum;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.