Given the following for loop :
const int Z=25;
for(int i=0,sum=0;i sum +=i;}
cout<< sum;
Write equivalent while loop for above code
Answer:
const int Z= 25;
int i=0, sum=0;
while i
{
sum+=I;
i++;
}
cout<< sum;
Write a C++ program to check whether the given number is palindrome or not
Answer:
#include
int main()
{
int n, num, digit,rev=0;
cout<< “Input the number(max 32767) :” ;
cin>> num ;
n=num;
do
{
digit= num%10;
rev = (rev*10) + digit ;
num= num/10;
}
while(num!= 0);
cout<< rev ;
if(n== rev)
cout<< “ The number is palindrome” ;
else
cout<< “ The number is not a palindrome “;
return 0;
}
Write a C++ program to print fibonacci series i.e. 0 1 1 2 3 5 8
Answer:
#include
Int main()
{unsigned long first , seconf, third,n;
first= 0;
second= 1;
cout<< “how many element (>5)?” ;
cin>> n;
cout<< “fibonacci series”;
cout<< first << “ “<< second ;
for (int i=2;i {
third = first + second ;
cout<< “” << third;
first= second;
second= third ;
}
return 0 ;
}
Write a program to swap two values
Answer:
#include
int main()
{
void swap(int&, int&);
int a,b;
a=7;
b=4;
cout << “a=”<< a << “b=” << b<< “\n”;
swap(a,b);
cout << “a=”<< a << “b=” << b;
return 0;
}
void swap(int &x, int &y)
{
int temp ;
temp = x;
x=y;
y= temp ;
}
Write a C++ program that checks whether the given character is alphanumeric or a digit.Add appropriate header file.