You are on page 1of 15

PROGRAM TO FIND AVG

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,sum,avg;
cout<<"enter three no."<<endl;
cin>>a>>b>>c;
sum=a+b+c;
cout<<"sum=";
cout<<sum;
avg=sum/3;
cout<<"avg=";
cout<<avg;
getch();
}

PROGRAM OF A CLASS
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
char name[20];
int rollno;
char address[50];
int Age;
public:
void input();
void display();
};
void student::input()
{
cout<<"\nEnter name of the student:";
gets(name);
cout<<"\nEnter roll no.:";
cin>>rollno;
cout<<"\nEnter address:";
gets(address);
cout<<"\nEnter age:";
cin>>Age;
}
void student::display()
{

cout<<"\nStudent Details";
cout<<"\nName:";
puts(name);
cout<<"\nRoll no.:"<<rollno;
cout<<"\nAddress:";
puts(address);
cout<<"\nAge:"<<Age;
}
void main()
{
clrscr();
student s[5];
for(int i=0;i<5;i++)
{
cout<<"Enter Details for student "<<i+1;
s[i].input();
}
for(int j=0;j<5;j++)
{
cout<<"Details of student "<<i+1;
s[i].display();
}
getch();
}

FACTORIAL USING CLASS

#include<iostream.h>
#include<conio.h>
class fact
{
int f,a;
public:
void input();
int calc();
void output();
};
void fact::input()
{
cout<<"enter the no.";
cin>>a;
}
int fact::calc()
{
f=1;
while(a)
{
f=f*a;
a--;
}
return f;
}
void fact::output()
{
cout<<"factorial is "<<endl;

cout<<f;
}
void main()
{
clrscr();
int output;
fact s;
s.input();
output=s.calc();
cout<<output;
getch();
}

FIBONACCI SERIES USING CLASS


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

class fib
{
int n;
int a,b,c;
public:
void input();
void calc();
};
void fib::input()
{
cout<<"enter no. of term"<<endl<<n;
}
void fib::calc()
{
a=0;
b=1;
cout<<a<<b;
for(int i=1;i<n;i++)
{
a=b;
b=c;
c=a+b;
cout<<c;
}
}
void main()
{
fib f;

f.input();
f.calc();
getch();
}

FIBONACCI SERIES
#include<iostream.h>
#include<conio.h>
void main()
{
int size,a,b,c=0;

cout<<"enter no. of fibonacci series"<<endl;


cin>>size;
a=0;
b=1;
cout<<a;
for(int i=2;i<=size;i++)
{
a=b;
b=c;
c=a+b;
cout<<c;
}
getch();
}

PROGRAM OF A PALINDROME
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
int x,i,j,flag=0;
char a[100];
cout<<"\n enter the string : ";
gets(a);
x=strlen(a);
for(i=0,j=x-1;i<x/2;i++,j--)
{
if(a[i]!=a[j])
{
flag=1;
break;
}
}
if(flag==0)
cout<<" \n string is a palindrome";
else
cout<<"\n string is not palindrome";
getch();
}

PATTERN PROGRAM
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,k,size;
for(i=5;i>=0;i--)
{
cout<<endl;
for(j=5;j>i;j--)
{
cout<<" ";
}
for(k=1;k<=i;k++)
{
cout<<" "<<k;
}
}
getch();
}

You might also like