You are on page 1of 11

1.

Program to display

pattern

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a,b;
a=65;
for(int i =1;i<10;i++)
{
for(int u=0;u<i;u++)
{
cout<<char(a+u);
}
cout<<endl;
}
getch();
}

2.Program to display

pattern

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<10;i++)
{
for(int uu=7;uu>=3;uu--)
cout<<"*";
for(int yyy=10;yyy>=i;yyy-=1)
cout<<" ";
for(int uuu=7;uuu>=3;uuu--)
cout<<"*";
for(int yy1=10;yy1<=i+10;yy1++)
cout<<" ";
for(int uu1=7;uu1>=3;uu1--)
cout<<"*";
for(int yyy1=10;yyy1>=i;yyy1-=1)
cout<<" ";
for(int uuu1=7;uuu1>=3;uuu1--)
cout<<"*";
cout<<endl;
}
for(int ii=1;ii<10;ii++)
{
for(int uu=7;uu>=3;uu--)
cout<<"*";

for(int yyy=0;yyy<=ii;yyy++)
cout<<" ";
for(int uuu=7;uuu>=3;uuu--)
cout<<"*";
for(int yy1=10;yy1>=ii;yy1--)
cout<<" ";
for(int uu1=7;uu1>=3;uu1--)
cout<<"*";
for(int yyy1=0;yyy1<=ii;yyy1++)
cout<<" ";
for(int uuu1=7;uuu1>=3;uuu1--)
cout<<"*";
cout<<endl;
}
getch();
}

3.Program to accept Length and breadth and calculate area,


perimeter
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
char ch,ch1;
float l,b,peri,area,diag;
cout<<" Rectangle Menu";
cout<<"1. Area 2.Perimeter 3.Diagonal 4.Exit"<<endl;
cout<<"Enter choice";
do
{
cin>>ch;
if(ch=='1'||ch=='2'||ch=='3')
{
cout<<"Enter length and breadth ";
cin>>l>>b;
}
switch(ch)
{
case'1':area=l*b;
cout<<"Area ="<<area;
break;

case'2':peri=2*(l+b);
cout<<"Perimeter "<<peri;
break;
case'3':diag=sqrt((l*l)+(b*b));
cout<<"Diagonal "<<diag;
break;
case'4':cout<<"Breaking";
break;
default:cout<<"Wrong choice";
cout<<"Enter a valid one";
break;
}
cout<<"Want to enter more ???";
cin>>ch1;
if(ch1=='y'||ch1=='Y')
cout<<"Again enter choice";
}while(ch1=='y'||ch1=='Y');
getch();
}

4.Program to display Fibonacci Sequence


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int first,second,third,n;
first=0;
second=1;
third=0;
cout<<"Enter the range"<<endl;
cin>>n;
cout<<"Fibonaci series";
cout<<first<<endl<<second<<endl;
for(int i=1;i<n;++i)
{
third=first+second;
cout<<third<<endl;
s
first=second;
second=third;
}
getch();
}

5.Program to display three numbers in descending order


#include<iostream.h>
#include<conio.h>
void main()
{

float a,b,c,big,big2,big3;
cout<<"Enter three numbers";
cin>>a>>b>>c;
big=a;
if(b>big)
big=b;
if(c>big)
big=c;
if(a==big)
{
if(b>c)
{
big2=b;
big3=c;
}
else
{
big2=c;
big3=b;
}
}
else if(b==big)
{
if(a>c)
{
big2=a;
big3=c;
}
else
{
big2=c;
big3=a;
}
}
else if(c==big)
{
if(a>b)
{
big2=a;
big3=b;
}
else
{
big2=b;
big3=a;
}
}
cout<<big<<" "<<big2<<" "<<big3<<endl;
getch();
}

6.Program to reverse a string


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char str1[25],str2[25];
int i,k,x1;
cout<<"Enter first string ";
gets(str1);
k=strlen(str1);
for(i=0;str1[i]!='\0';i++)
{
str2[k-i]=str1[i];
}
cout<<"The reversed string is"<<endl;
for(x1=0;x1<k;x1++)
{
cout<<str2[x1];
}
getch();
}

7.Program to check whether a string is palindrome


#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char s1[10], s2[10];
cout<<"Enter string 1:";
gets(s1);
cout<<"Enter string 2:";
gets(s2);
cout<<strcat(s1,s2);
getch();
}

8.Program to count the lowercase characters in a string


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

#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
int chcount=0;
const char ent='\n';
char ch;
cout<<"Enter character";
cin.get(ch);
while(ch!=ent)
{
if(ch>='a'&&ch<='z')
{
chcount++;
cout.put(ch);
}
cin.get(ch);
}
cout<<"the number of character ="<chcount<<'\n';
getch();
}

9.Program to concatenate two strings


#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char s1[10], s2[10];
cout<<"Enter string 1:";
gets(s1);
cout<<"Enter string 2:";
gets(s2);
cout<<strcat(s1,s2);
getch();
}

10.Program to add two arrays


#include<iostream.h>
#include<conio.h>
void main()

int i, j, k;
int A[5], B[5], C[10];
cout<<"Enter array A:";
for(i=0; i<5; i++)
cin>>A[i];
cout<<"Enter array B:";
for(j=0;j<5;j++)
cin>>B[j];
for(i=0,k=0; i<5;k++, i++)
C[k]=A[i];
for(k=5, i=0; i<5; k++, i++)
C[k]=B[i];
cout<<"\nArray C:";
for(k=0;k<10;k++)
cout<<C[k]<<" ";
getch();
}

11.Program to add row in matrice


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[3][3], sum;
cout<<"Enter matrix A:";
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
cin>>A[i][j];
}
for(i=0; i<3; i++)
{
sum=0;
for(int j=0; j<3; j++)
sum=sum+A[i][j];
cout<< "nSum of row"<<i+1<< " is " <<sum<<"\n";
}
getch();
}

12.Program to multiply to martix


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int A[3][3], B[3][3], C[3][3];

cout<<"Enter matrix A:";


for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
cin>>A[i][j];
}
cout<<"Enter matrix B:";
for(i=0; i<3; i++)
{
for(int j=0; j<3; j++)
cin>>B[i][j];
}
cout<< "nMatrix A X matrix B";
for(i=0; i<3; i++)
{
cout<<"\n";
for(int j=0; j<3; j++)
{
int sum=0;
for(int k=0; k<3; k++)
{
sum+=A[i][j]*B[k][j];
}
cout<<sum<<" ";
}
}
getch();

13.Program to replace a certain element in array with 0


#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[9], n, t, k;
cout<<"Enter array:";
for(int i=0; i<9; i++)
cin>>arr[i];
cout<<"Enter number:";
cin>>n;
for(i=0; i<9; i++)
{
if(arr[i]==n)
arr[i]=0;
}
for(i=0; i<9; i++)
cout<<arr[i]<<"\n";
cout<<"\n";
for(k=0;k<2; k++)

{
for(i=8; i>=0; i--)
{
if(arr[i]==0)
{
for(int j=i;j>0;j--)
{
t=arr[j];
arr[j]=arr[j-1];
arr[j-1]=t;
}
}
}
}
cout<< "Array after replacing "<<n<<": ";
for(i=0; i<9; i++)
cout<<arr[i];
getch();
}

14.Program to print a students result

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
struct Student
{
int rollno;
char name[21];
float marks[5];
char grade;
};
Student learner;
void main()
{
clrscr();
cout<<"Enter Roll No: ";
cin>>learner.rollno;
cout<<"Enter Name ";
gets(learner.name);
cout<<"Enter marks in 5 subjects"<<endl;
for(int i=0;i<5;i++)
{
cout<<"Subject"<<i+1;
cin>>learner.marks[i];
}

float avg,total;
total=(learner.marks[0]+learner.marks[1]+learner.marks[2]+learner.marks[3]+lear
ner.marks[4]);
avg=total/5;
cout<<"Student result"<<endl;
cout<<"Roll No:"<<learner.rollno<<"\t";
cout<<"Name";
cout.write(learner.name,21);
cout<<"Total Marks"<<total;
cout<<"Average"<<avg;
getch();
}

15.Program to calculate distance in feet and inches by structures


#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
struct Distance
{
int feet;
int inches;
};
void main()
{
clrscr();
Distance length1,length2;
void prnsum(Distance l1,Distance l2);
cout<<"Enter length 1:"<<endl;
cout<<"Feet:";
cin>>length1.feet;
cout<<"Inches";
cin>>length1.inches;
cout<<"Enter length2:"<<endl;
cout<<"Feet";
cin>>length2.feet;
cout<<"Inches";
cin>>length2.inches;
prnsum(length1,length2);
}
void prnsum(Distance l1,Distance l2)
{
Distance l3;
l3.feet=l1.feet+l2.feet+(l1.inches+l2.inches)/12;
l3.inches=(l1.inches+l2.inches)%12;
cout<<"Total feet"<<l3.feet<<endl;

cout<<"Total incehs"<<l3.inches<<endl;

getch();
}

You might also like