You are on page 1of 2

SOULTION OF MID EXAM 2nd D

Q.3 Write a program in C++ to compute Fibonacci series for the number by user. #include <iostream.h> void main() { int a,b,x,y,num1,ct; a=0; b=1; cout << "Enter the number of terms (less than 25) : " << endl; cin>>num1; cout << a << endl; cout << b << endl; for (ct=1;ct<=num1-2;ct++) { x=a+b; cout << x << endl; y=a; a=b; b=x; } }

Q.2 Write a Program in C++ to enter an integer and output it in the reversed form by using function.
#include <iostream.h> void main() { long int num1,num2,rnum=0; cout << "Enter an integer : " << endl;

cin>>num1; num2=num1; do { rnum=rnum*10; int digit=num1%10; rnum+=digit; num1/=10; } while (num1); cout << "The integer you typed is " << num2 << "." << endl; cout << "The reversed integer is " << rnum << "." << endl; } Q.1 Write a program in C++to find out the sum of the digits present in an integer.

#include<iostream.h>
void main() { int n,num,x,sum=0; cout<<"Enter a number = "; cin>>n; while(n>0) { x=n%10; sum=sum+x; n=n/10; } cout<<"Sum of digits of a number="<<sum<<endl; }

You might also like