Palindrome


#include<iostream.h>
#include<conio.h>
#include<string.h>

void main()
{clrscr();
     char str[25],str1[25];	
     cout<<"Enter a string: ";
	
     gets(str);

     strcpy(str1,str);
     strrev(str);
	if(strcmp(str,str1)!=0)
	{
	     cout<<"string is not palindrome";
	}
	else
	{
	      cout<<"string is a palindrome";
	}

	  cout<<endl;
getch();
}

Print all odd nos till 50


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n=1;
do
{
cout<<n<<endl;
n=n+2;
}
while(n<=50);
getch();
}
**********output***********
1
3                                                                            
5                                                                            
7                                                                            
9                                                                            
11                                                                            
13                                                                            
15                                                                            
17                                                                            
19                                                                            
21                                                                            
23                                                                            
25                                                                            
27                                                                            
29                                                                            
31
33                                                                            
35                                                                            
37                                                                            
39                                                                            
41                                                                            
43                                                                            
45                                                                            
47  

Algorithm:
1. Start
2. Set n=1
3. Write n
4. Increment n
5. Check if no<50
     if true then:
     a)Go to step 2
    if false then:
     b)go to step 5
6. Stop

                                                                        
49

GCD & LCM


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,no1,no2,i,temp;
cout<<"enter 2 nos";
cin>>a>>b;
no1=a;
no2=b;
while(no2)
{
int temp=no2;
no2=no1%no2;
no1=temp;
}
cout<<"\n GCD="<<no1;
for(i=a; i<=a*b; i++)
{
if(i%a==0 && i%b==0)
{
cout<<"\n LCM="<<i;
break;
}
}

getch();
}

******output******
enter 2 nos 4
6                                                                            
                                                                             
 GCD=2                                                                        
 LCM=12                                                                      
                                                                             
 Algorithm:
1.Read a,b,no1,no2,temp & i.
2.While no2 not equal to zero
         a)  Set no2=no1/no2 & no1=temp                                                                          
         b)  Write G.C.D = no2
3.for initialize integer i=a;i<=a*b;i++
       {
           if   i%a=0 & i%b=0
          Write: L.C.M
        [End of If structure]
        [End of For structure]
4.Exit                                                            
             




                                                              
                                                           
                                           

                                                   

Armstrong number


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,temp,sum=0,d=0;
cout<<"enter the number";
cin>>a;
temp=a;
while(a)
{
d=a%10;
sum=sum+(d*d*d);
a=a/10;
}
if(sum==temp)
{
cout<<"The no.is armstrong";
}
else
{
cout<<"The no.is not armstrong";
}
getch();
}
******output*******
enter the number153
The no.is armstrong    

Algorithm:
1. Start
2. Read A
3. Set temp=A
4. Check while (A)
    if true:
    a)Set D=A%10
    b)Set sum=sum + (D*D*D)
    c)Set A=A/10
    [end of while structure]
5. Check if sum = temp
    a) Write: The no. is amstrong
6. else
    a) Write: The no. not is amstrong 
    [end of if else structure]  
7. Stop