0% found this document useful (0 votes)
80 views9 pages

#Include #Include #Include Using Namespace Using Namespace Class Int Char Char Int Double Public Void

The document contains a C++ program that performs various mathematical operations on numbers. The program includes functions to check if a number is prime, calculate the factorial of a number, generate the Fibonacci series, calculate the sum of digits in a number, reverse digits of a number, and check if two numbers are co-prime. The main function uses a switch case to call the appropriate function based on user input and loops until the user enters 'n' to exit.

Uploaded by

Neeraj Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views9 pages

#Include #Include #Include Using Namespace Using Namespace Class Int Char Char Int Double Public Void

The document contains a C++ program that performs various mathematical operations on numbers. The program includes functions to check if a number is prime, calculate the factorial of a number, generate the Fibonacci series, calculate the sum of digits in a number, reverse digits of a number, and check if two numbers are co-prime. The main function uses a switch case to call the appropriate function based on user input and loops until the user enters 'n' to exit.

Uploaded by

Neeraj Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Q 2. write a program in c++.net to generate percentage of student. Ans #include "stdafx.h" #include<iostream> #include<conio.

h> using namespace std; using namespace System; class stud { int m1,m2,m3,m4,m5; char name[20]; char roll[20]; int total; double per; public: void getdata() { cout<<"enter student name"; cin>>name; cout<<"Enter Roll No."; cin>>roll; cout<<"enter marks for sub 1"; cin>>m1; cout<<"enter marks for sub 2"; cin>>m2; cout<<"enter marks for sub 3"; cin>>m3; cout<<"enter marks for sub 4"; cin>>m4; cout<<"enter marks for sub 5"; cin>>m5; total=m1+m2+m3+m4+m5; per=total/5; } void dispdata() { cout<<"\nStudent Name : "<<name<<"\nRoll No. : "<<roll<<"\nTotal Marks : "<<total<<"\nPercentage : "<<per; } }; void main() { stud st; st.getdata(); st.dispdata(); getch(); }

Ans. enter student name deepti Enter Roll No.052 enter marks for sub 1 56 enter marks for sub 2 56 enter marks for sub 3 56 enter marks for sub 4 56 enter marks for sub 5 56 Student Name : deepti Roll No. : 052 Total Marks : 280 Percentage : 56

Q write a program in c++.net to perform manipulation with no. prime no fibonacci series factorial coprime reverse of no sum of digit Ans
#include <iostream> #include<conio.h> #include<math.h> using namespace std; void prime(); void fact(); void fib(); void sumdig(); void revdig(); void coprime(); void main() { char c; int a; do { cout<<"To Find Prime No. press 1 \nTo find Factorial press 2 \nTo find Fibonacci series press 3 \nTo Find Sum of Digits Press 4\nTo Reverse the No. press 5\nTo find Co prime press 6 \n exit 7"; cin>>a; switch(a) { case 1: prime(); break; case 2: fact(); break; case 3: fib(); break; case 4: sumdig(); break; case 5: revdig(); break; case 6: coprime(); break; case 7: exit(0); default : cout<<"Wrong Choice"; } cout<<"/ndo you want to continue";

cin>>c; } while(c!='n'); getch(); } void prime() { int x,temp,flag,i; cout<<"enter any no. to find that no. is prime or not"; cin>>x; if(x>=2) { for(i=2;i<x;i++) { temp=x%i; if(temp==0) { flag=0; break; } else flag=1; } if(flag==0) cout<<x<<" is not a prime number"; else cout<<x<<" is a prime no."; } else if(x>0 && x<2) { cout<<x<<" is a prime no."; } } void fact() { int x,temp,i; temp=1; cout<<"enter any no. to find Factorial of that number"; cin>>x; for(i=1;i<=x;i++) { temp=temp*i; } cout<<"Factorial of "<<x<<" is "<<temp; } void fib() { int x,temp,a,b,n; cout<<"enter how many no.s should be there in Fibonacci Series"; cin>>x; n=2; a=0; b=1; if(x<3 && x>0) { if(x==1) cout<<a;

else { cout<<a; cout<<"\n"<<b; }

} else {

cout<<"\n"<<a; cout<<"\n"<<b; while(1) { if(x==n) break; else { temp=a+b; a=b; b=temp; n += 1; cout<<"\n"<<temp; } } } } void sumdig() { int a,sum,b,x; sum=0; cout<<"Enter a number"; cin>>a; x=a; while(a!=0) { b=a%10; a=a/10; sum=sum+b; } cout<<"sum of Digits of "<<x<<" is "<<sum; } void revdig() { int a,x,n; double rev,b; rev=0; n=0; cout<<"Enter a number"; cin>>a; x=a; while(a!=0) { n=n+1; a=a/10; } a=x; n=n-1;

while(x!=0) { b=x%10; x=x/10; rev=rev+b*pow(10.0,n); n=n-1; } cout<<"Rev of No. "<<a<<" is "<<rev; } void coprime() { int a,b,x,y,flag,i; cout<<"enter two no.s"; cin>>a>>b; if(a<b) { for(i=2;i<b;i++) { x=a%i; if(x==0) { y=b%i; if(y==0) { flag=1; break; } } flag=0; } } else { for(i=2;i<a;i++) { x=b%i; if(x==0) { y=a%i; if(y==0) { flag=1; break; } } flag=0; } } if(flag==0) cout<<"no. is co-prime"; else cout<<"no is not co-prime";

Output To Find Prime No. press 1 To find Factorial press 2 To find Fibonacci series press 3 To Find Sum of Digits Press 4 To Reverse the No. press 5 To find Co prime press 6 exit 7 1 enter any no. to find that no. is prime or not7 7 is a prime no. do you want to continuey To Find Prime No. press 1 To find Factorial press 2 To find Fibonacci series press 3 To Find Sum of Digits Press 4 To Reverse the No. press 5 To find Co prime press 6 exit 7 2 enter any no. to find Factorial of that number5 Factorial of 5 is 120 do you want to continuey To Find Prime No. press 1 To find Factorial press 2 To find Fibonacci series press 3 To Find Sum of Digits Press 4 To Reverse the No. press 5 To find Co prime press 6 exit 7 3 enter how many no.s should be there in Fibonacci Series5 0 1 1 2 3 do you want to continuey To Find Prime No. press 1 To find Factorial press 2 To find Fibonacci series press 3 To Find Sum of Digits Press 4 To Reverse the No. press 5 To find Co prime press 6 exit 7

4 Enter a number456 sum of Digits of 456 is 15 do you want to continuey To Find Prime No. press 1 To find Factorial press 2 To find Fibonacci series press 3 To Find Sum of Digits Press 4 To Reverse the No. press 5 To find Co prime press 6 exit 7 5 Enter a number456 Rev of No. 456 is 654 do you want to continuey To Find Prime No. press 1 To find Factorial press 2 To find Fibonacci series press 3 To Find Sum of Digits Press 4 To Reverse the No. press 5 To find Co prime press 6 exit 7 6 enter two no.s35 6 no. is co-prime do you want to continue n

You might also like