Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Provblem #11:

A program to take inputs the number of students in the class.If then inputs the
marks of these students and display the highest and second highest marks.

solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int s,count = 2, highest,marks,highest_2;
cout << "Enter number of students:";
cin >> s;
cout << endl << "Enter marks:";
cin >> marks;
if(marks > highest_2)
highest = marks;
else
highest_2 = marks;
while(count < s)
{
cout << endl << "Enter marks:";
cin >> marks;
if((marks > highest_2) && (marks < highest))
highest_2 = marks;
if(marks > highest_2)
highest = marks;
count++;
}
cout << endl << "Highest marks are:" << heighest;
cout << endl << "2nd highest marks are:" << highest_2;
return 0;
}

Problem # 19:
Write a program to calculate and display sum of the following series using for
loop:
1! + 2! + 3! + 4! + 5!

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int f,c,sum = 0, n;
for(n = 1; n < 5; n++)
{
f = 1;
for(c = 1; c <= n; c++)
{
f = f * c;
}
sum = sum + f;
}
cout << "Sum of the series is: " << sum ;
return 0;
}

You might also like