0% found this document useful (0 votes)
10 views

6 Semester Basic Lab

The document contains code snippets for 5 C++ programs: 1) Check if a number is even or odd. 2) Calculate the sum of natural numbers. 3) Display the Fibonacci series. 4) Check if a number is a palindrome. 5) Reverse a given number.

Uploaded by

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

6 Semester Basic Lab

The document contains code snippets for 5 C++ programs: 1) Check if a number is even or odd. 2) Calculate the sum of natural numbers. 3) Display the Fibonacci series. 4) Check if a number is a palindrome. 5) Reverse a given number.

Uploaded by

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

6 SEMESTER ALL BASIC LBA

//1.Write a C++ Program to Check Whether Number is


Even or Odd.
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter an integer: ";
cin >> n;
if ( n % 2 == 0)
cout << n << " is even.";
else
cout << n << " is odd.";
return 0;
}
// 2.Write a C++ Program to Calculate Sum of Natural
Numbers

#include <iostream>
using namespace std;
int main() {
int n, sum = 0;
cout << "Enter a positive integer: ";
cin >> n;
for (int i = 1; i <= n; i++) {
sum = sum+ i;
}
cout << "Sum = " << sum;
return 0;
}
// 3.Write a C++ Program to Display Fibonacci Series
// bing ai ar ans
#include <iostream>
using namespace std;
int main() {
int n, first=0 ,second=1 , next ;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Fibonacci Series up to " << n << " terms:\n";
cout << first<<" " << second <<" ";
for (int i = 2 ;i < n ; i++) {
next = first + second;
cout << next << " ";
first = second;
second = next;
}
return 0;
}
/ 3.Write a C++ Program to Display Fibonacci Series // anis sir ans

#include <iostream>
using namespace std;
int main() {
int first=0 ,second=1 , count=0 ,fibo ,n ;
cout << "Enter range : ";
cin >> n;
while ( count< n)
{
if(count<=1)
{
fibo=count ;
}
else {
fibo=first +second ;
first=second ;
second = fibo ;
}
cout<< fibo << " " ;
count++ ;
}
return 0;
}
4.Write a C++ Program to Check Whether a Number is
Palindrome or Not anisul sir
#include <iostream>
using namespace std;
int main() {
int num , temp , r ,sum=0 ;
cout << "Enter any number : ";
cin >> num;
temp= num ;
while (temp!=0)
{
r=temp%10;
sum=sum*10+r;
temp=temp/10;
}
if(num==sum)
cout<<"Palindrome nomber" ;
else cout<<"Not palindrome"
;
return 0;
}
5.Write a C++ Program to Reverse a Number // anis sir
#include <iostream>
using namespace std;
int main() {
int num , temp , r ,sum=0 ; akhane r= remainder
cout << "Enter any number : ";
cin >> num;
temp= num ;
while (temp!=0)
{
r=temp%10;
sum=sum*10+r;
temp=temp/10;
}
cout<<"Reverse of number :"<<sum ;
return 0;
}

You might also like