Question #47629

1. Draw the flowchart and write a c program that reads in a number n and then outputs the sign off the square from 1 to n

Ex. If n=3, output should be 14 because 1²+2²+3²=1+4+9=14

2. In a class of n students print the total no of female students and the total no of male students and at the end print the total no of total no of students in n class both males and females.

Expert's answer

Answer on Question #47629 - Engineering, Other

1. Draw the flowchart and write a c program that reads in a number n and then outputs the sign off the square from 1 to n

Ex. If n=3, output should be 14 because 1²+2²+3²=1+4+9=14

Solution.

#include <iostream>
using namespace std;
int main()
{
int n=0;
cout<<"Enter the number: ";
cin>>n;
int k=0;
for(int i=1; i<=n; i++)
{
k+=powf(i,2);
}
cout<<"Result: "<<k;
//Stop console
cin.get();
cin.get();
return 0;
}</iostream>
![img-0.jpeg](img-0.jpeg)
2. In a class of n students print the total no of female students and the total no of male students and at the end print the total no of total no of students in n class both males and females
# Solution

c

include <iostream>

using namespace std;

const int N = 10;

class Student

{

bool male;

public:

void setMale(bool male)

{

this->male=male;

}

bool getMale()

{

return this->male;

}

};

class Class

{

public:

Student st[N];

};

```</iostream>


int main()
{
Class cs[15];
cs[N].st[1].setMale(false);
cs[N].st[5].setMale(false);
int male=0, female=0;
for(int i=0; i<N; i++)
{
if(cs[N].st[i].getMale())
{
male++;
}
else
{
female++;
}
}
cout<<"The total no of female students: "<<female<<endl;
cout<<"The total no of male students:"<<male<<endl;
cout<<"The both males and females:"<<male+female<<endl;
//Stop console
cin.get();
cin.get();
return 0;
}


https://www.assignmentexpert.com/


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS