Name:-Roll No.: - Course
Name:-Roll No.: - Course
:COURSE :-
class palindrome { public: palindrome(){} ~palindrome(){} void isPalindrome ()//function to check palindrome { char str[100]={}; int len=0; cout<<"Enter String=>"; cin>>str; len=strlen(str)-1;// we are trying to get the middle element of array starting at zero for(int i=0;i<=len;i++) { if(str[i]!=str[len-i])//checking last and first element and then subtraction of both { cout<<"Not Palndrome"<<endl; return ; } } cout<<"Is Palndrome<<endl"; } }; int main() { palindrome p; p.isPalindrome(); return 0; }
OUTPUT:-
PROGRAM NO.Program to check whether a no. is prime or not and print all prime nos. from 1 to 50.
#include "iostream" #include "cstring" using namespace std; class prime { public: prime(){} ~prime(){} void isPrime() { for(int i=1;i<=50;i++)//looping from 1 to 50 {
OUTPUT:-
if(i<4)//1-3 are prime by default { cout<<i<<" is prime"<<endl; } else { for(int j=2;j<i;j++)/*rest all numberss are checked for remainder starting from 2 upto n-1*/ { if(i%j==0) { cout<<i<<" is not prime"<<endl; break; } else if(i==j+1) { cout<<i<<" is prime"<<endl; } } } } }; }
int main() { int first=0,second=1,third,i,n; cout<<"How many nos. do you want to print?"<<endl; cin>>n; cout<<first<<" "<<second; for(i=3;i<=n;i++) { third=first+second; cout<<" "<<third; first=second; second=third; } getch(); }
OUTPUT:-
PROGRAM NO.Program to take a date from user and tell how many days have passed till that date since the beginning of that year
#include<iostream>
#include<stdio.h> #include<conio.h> using namespace std; inline int leap(int); struct date { int d,m,y; }dt; int main() { int days=0,m; cout<<"Enter date (dd/mm/yyyy) i.e. 01/02/2012 "<<endl; scanf("%2d/%2d/%4d",&dt.d,&dt.m,&dt.y); switch(dt.m) { case 12: days+=30; case 11: days+=31; case 10: days+=30; case 9: days+=31; case 8: days+=31; case 7: days+=30; case 6: days+=31; case 5: days+=30; case 4: days+=31; case 3: days+=28; case 2: days+=31; } /* in case of January there is no month before that hence only date of January will be added */ cout<<"The total days elapsed since January 1, "; cout<<dt.y<<" are "<<dt.d + leap(dt.y) + days; getch(); return 0; } inline int leap(int y) { if(y%4==0 || y%100==0) return 1; return 0; }
OUTPUT:-
PROGRAM NO.#include <iostream> #include<conio.h> using namespace std; int flag=0; class time1 {
private: int hour,min,sec; public: time1(): hour(0), min(0), sec(0) { } time1(int h,int m,int s) { hour=h; min=m; sec=s;
} void gettime1() { cout<<"Enter time1:- "; cin>>hour; cin>>min; cin>>sec; } void addtime1(time1 t1,time1 t2) { sec=t1.sec+t2.sec; if(sec>=60) { min++; sec=sec-60; } min=min + t1.min+t2.min; if (min>60) { hour++; min=min-60; } hour=hour+ t1.hour + t2.hour; if (hour>=12) { hour=hour-12; flag=1; } } void showtime1() { if (flag==0) cout<<hour<<":"<<min<<":"<<sec<<" am"; else if(flag==1) cout<<hour<<":"<<min<<":"<<sec<<" pm"; } }; int main()
OUTPUT:-
PROGRAM NO.Program to convert temperature given in Fahrenheit to Celsius and Celsius to Fahrenheit
#include<iostream> #include<conio.h> using namespace std; int main() { float ct,ft; int a,ch=1; while(ch==1) { cout<<"press 1 to convert Celsius to Fahrenheit "<<endl; cout<<"2 to convert Fahrenheit to Celsius"<<endl<<"enter choice : "; cin>>a; switch(a) { case 1 :cout<<"enter the temperature in Celsius : "; cin>>ct; ft=9*ct/5+32; cout<<"temp in Fahrenheit : "<<ft; break; case 2:cout<<"enter the temperature in Fahrenheit : "; cin>>ft; ct=(ft-32)*5/9; cout<<"temp in Celsius : "<<ct; break; } cout<<endl<<"do you want to continue (press 1 for yes and 2 for no) : "; cin>>ch; } getch(); return 0; }
OUTPUT:-