0% found this document useful (0 votes)
44 views15 pages

Das Assignment

The document contains C++ code snippets for solving various problems involving data structures and algorithms. These include programs to calculate the factorial of a number, print the Fibonacci series, check if a number is a palindrome, calculate simple and compound interest, find student marks and grade, and print a pyramid pattern. For each problem, the code input and output are shown for sample test cases.

Uploaded by

Ridum Aggarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views15 pages

Das Assignment

The document contains C++ code snippets for solving various problems involving data structures and algorithms. These include programs to calculate the factorial of a number, print the Fibonacci series, check if a number is a palindrome, calculate simple and compound interest, find student marks and grade, and print a pyramid pattern. For each problem, the code input and output are shown for sample test cases.

Uploaded by

Ridum Aggarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DSA Assignment C++

1| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

// W.A.P. using C++ for finding a factorial of a positive integer.

Input:
#include<iostream>

using namespace std;

int main()

int a,i;

long fact=1;

cout<<"Enter the positive integer:-";

cin>>a;

for(i=1;i<=a;i++)

fact=fact*i;

cout<<"Factorial of given no. is= "<<fact<<endl;

return 0;

2| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

Output:
For entered value 5

3| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

// 1) WAP using C++ to print Fibonacci Series.

Input:
#include<iostream>

using namespace std;

int main()

int n1=0,n2=1,n3,i,a;

cout<<"Enter the no.of elements in fibonacci series: ";

cin>>a;

cout<<n1<<""<<n2<<"";//printing 0 and 1

for (i=2;i<a;++i)

n3=n1+n2;

cout<<n3<<"";

n1=n2;

n2=n3;

return 0;

4| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

Output:
For Entered value - 5

5| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

// WAP using C++ to check whether the no. is Palindrom or not.

Input:
#include<iostream>

using namespace std;

int main()

int a,n,digit,rev=0;

cout<<"Enter the number to check wether it is palindrome or not:";

cin>>a;

for(n=a;n!=0;)

digit=n%10;

rev=(rev*10)+digit;

n=n/10;

cout<<"The reverse of the number is "<<rev<<endl;

if (a==rev)

cout<<"The number is palindrome";

else
6| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >
DSA Assignment C++

cout<<"The number is not palindrome";

return 0;

Output:
For entered number 454.

For entered number 456.

7| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

//WAP using C++ to find Simple intrest and Compound intrest.

Input:
#include <bits/stdc++.h>

using namespace std;

int main()

int p,t;

float r,si,ci,a1,a2;

cout<<"Enter the Principal amount:";

cin>>p;

cout<<"Enter the Rate of intrest(in %):" ;

cin>>r;

cout<<"Enter the Time (in years):";

cin>>t;

si=p*r*t/100;

ci=p*pow((1+r/100),t)-p;

a1=si+p;

a2=ci+p;

cout<<"Simple Intrest="<<si<<" Total Amount="<<a1<<"\nCompound


Intrest="<<ci<<" Total Amount="<<a2<<endl;

return 0;

8| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

Output:
For Principal Amount :- 45000

Percent:- 12%

Time:- 5 years

9| b y Ri dum Agg ar wal< MCA 1 s t yea r R oll n o. 81 >


DSA Assignment C++

// WAP using C++ to find total marks, average, percentage of a


student and also divide into Grades.

Input:
#include<iostream>

using namespace std;

int main()

float eng,hindi,maths,sci,sst,max;

float avg,per,total;

cout<<"Enter the marks of subjects(Eng,Hindi,Maths,Sci,Sst respectively)\n";

cin>>eng>>hindi>>maths>>sci>>sst;

cout<<"Enter the maximum marks for each subject";

cin>>max;

total=eng+hindi+maths+sci+sst;

avg=total/5;

per=(total/(max*5))*100;

cout<<"Total marks="<<total<<"\nAverage
Marks="<<avg<<"\nPercentage="<<per<<"%"<<endl;

cout<<"Grade:- ";

if (per>=75) cout<<"A";

else if(per>=50) cout<<"B";

else if(per>=33) cout<<"C";

10 | b y R i d u m A g g a r w a l < M C A 1 s t y e a r R o l l n o . 8 1 >
DSA Assignment C++

else cout<<"Fail";

return 0;

Output:

11 | b y R i d u m A g g a r w a l < M C A 1 s t y e a r R o l l n o . 8 1 >
DSA Assignment C++

//WAP in C++ to print a pattern .

1) for given no. of times.

Input:
#include<iostream>

using namespace std;

void pat(int k,int j)

int n;

for (n=1;n<=5;n++)

if(n>=k)

cout<<"* ";

else if (j==1)

cout<<" ";

else

cout<<" ";

int main() {

int s,i,j,k=5,l;

12 | b y R i d u m A g g a r w a l < M C A 1 s t y e a r R o l l n o . 8 1 >
DSA Assignment C++

cout<<"Enter the no. of pyramids to be print- ";

cin>>s;

for(i=1;i<=5;i++)

for(j=1;j<=s;j++)

pat(k,j);

k--;

cout<<"\n";

return 0;

Output:
For entered Value 3

13 | b y R i d u m A g g a r w a l < M C A 1 s t y e a r R o l l n o . 8 1 >
DSA Assignment C++

14 | b y R i d u m A g g a r w a l < M C A 1 s t y e a r R o l l n o . 8 1 >
DSA Assignment C++

15 | b y R i d u m A g g a r w a l < M C A 1 s t y e a r R o l l n o . 8 1 >

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy