Worksheet 2.1
Worksheet 2.1
EXPERIMENT NUMBER - 1
PRACTICAL – 1.1.1
AIM OF THE EXPERIMENT – To find the average marks of a student of 5 subjects in a class.
ALGORITHM:- 1. Start.
2. Ask the user to enter the marks of the student.
3. Find the sum of the marks and then divide by 5 to find the average.
4. Print the result.
5. Stop.
FLOWCHART -
START
Print the
following STOP
results .
PROGRAM CODE:-
#include<iostream>
using namespace std;
int main()
{
int s1, s2, s3, s4, s5;
float avg,total;
cout<<"Enter marks of student :- ";
cin>>s1>>s2>>s3>>s4>>s5;
total= s1+s2+s3+s4+s5;
cout<<"Total marks of student :- "<<total<<endl;
avg=total/5;
cout<<"Average marks of student :- "<<avg;
return 0;
}
PROGRAM’S EXPLANATION (in brief) - This program is a simple C++ language program used to
explain, How we can find the average marks of the student. It intends to make calculations faster
and easier for all individuals.
4] To retrieve the output from the arithmetic method, select the print option.
OUTPUT:-
LEARNING OUTCOMES:–
Understanding the ways of execution and debugging the programs in C++ language.
Helps to build and compile a simple C++ language program to find the average marks of the
student.
PRACTICAL – 1.1.2
AIM OF THE EXPERIMENT – To swap the first and last digit of a number.
ALGORITHM – 1. Start.
2. Take the number from the user.
3. Find the first and last digit of the number provided.
4. Now, swap the first and last digit.
5. Print the new number.
6. Stop.
FLOWCHART -
START
Take the
number
from the
user.
Print the
results.
STOP
PROGRAM CODE:–
PROGRAM’S EXPLANATION (in brief) - This program is a simple C++ language program, used
for swapping the first and last digit of a number. It intends to make calculations faster and easier for
all individuals.
3] Take the number and write down the program’s input as well. As well as the variables.
4] To retrieve the output from the arithmetic method, select the print option.
RESULT –
LEARNING OUTCOMES –
Understanding the ways of execution and debugging the programs in C++ language.
Helps to build and compile a simple C++ language program to swap the first and last digit of a
number provided by the user.
PRACTICAL – 2.1.3
AIM OF THE PRACTICAL:- Write a program to generate the Fibonacci series up to the
user’s specified limit. Write all the missing terms (e.g. 4, 6, 7, 9, 10, 11, 12, 14, 15…)
also at the end.
ALGORITHM:- 1. Start.
2. Ask the user to enter the limit to generate the Fibonacci series.
3. Write the Fibonacci series between the limits.
4. Find the numbers that are missing from the series.
5. Print the result.
6. Stop.
FLOWCHART:-
START
Ask the
user to
enter the Find the numbers that
limit to are missing from the
generate series.
Print the
results.
STOP
PROGRAM’S CODE:-
//Write a program to print a series of arm-strong numbers from m to n.
m, n will be inputted by the user.
#include<stdio.h>
int main()
{
int i, j, cur, lastDigit, m, n;
long fact, sum;
printf("\n Enter the lower limit = ");
scanf("%d", &m);
printf("\n Enter the upper limit = ");
scanf("%d", &n);
printf("\n Armstrong numbers between %d to %d are = ", m,n);
for(i=m; i<=n; i++)
{
cur = i;
sum = 0;
while(cur > 0)
{
fact = 1;
lastDigit = cur % 10;
for( j=1; j<=3; j++)
{
fact = fact * lastDigit;
}
sum += fact;
cur /= 10;
}
if(sum == i)
{
printf("\n %d", i);
}
}
return 0;
}
PROGRAM’S EXPLANATION (in brief) - This program is a simple C language program, used to
find arm-strong numbers between the limits set by the user.
3] Take the limits and write down the program’s input as well. As well as the variables.
4] To retrieve the output from the arithmetic method, select the print option.
RESULT:-
LEARNING OUTCOMES:–
Helps to build and compile a simple C language program to find arm strong numbers
between the two limits.