0% found this document useful (0 votes)
53 views

Project of Computer

The document contains C++ programs to perform various tasks like: 1. Summing three numbers 2. Swapping two numbers 3. Finding the largest of three numbers 4. Converting lowercase to uppercase 5. Counting spaces, vowels, or characters in a string 6. Searching an element in an array 7. Summing and comparing two matrices 8. Checking if a number is a palindrome 9. Finding factors of a number 10. Printing multiplication tables 11. Calculating area of shapes 12. Finding simple interest 13. Checking if a number is prime 14. Calculating student marks, percentages, and grades.

Uploaded by

Rishabh Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Project of Computer

The document contains C++ programs to perform various tasks like: 1. Summing three numbers 2. Swapping two numbers 3. Finding the largest of three numbers 4. Converting lowercase to uppercase 5. Counting spaces, vowels, or characters in a string 6. Searching an element in an array 7. Summing and comparing two matrices 8. Checking if a number is a palindrome 9. Finding factors of a number 10. Printing multiplication tables 11. Calculating area of shapes 12. Finding simple interest 13. Checking if a number is prime 14. Calculating student marks, percentages, and grades.

Uploaded by

Rishabh Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

\* PROGRAME TO SUM OF THREE NO.

*\
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"\n Enter First no.=";
cin>>a;
cout<<"\n Enter Second no.=";
cin>>b;
cout<<"\n Enter Third no.=";
cin>>c;
d=a+b+c;
cout<<"\n Sum="<<d;
getch();
}
OUTPUT
/*PROGRAME TO SWAP NUMBER BETWEEN TO VARIABLES.*/

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"\n enter the first numbers=";
cin>>a;
cout<<"\n enter the second number=";
cin>>b;
c=a;
a=b;
b=c;
cout<<"\n the swap numbers are"<<"\n first number="<<a<<"\n second number="<<b;
getch();
}
OUTPUT
/*PROGRAME TO CHECK THE HIGHEST VALUE AMONG THREE

VARIABLES*/

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"\nenter value of a";
cin>>a;
cout<<"\nenter value of b";
cin>>b;
cout<<"\nenter value of c";
cin>>c;
if(a>b&&a>c)
cout<<"\n"<<a;
else
if(b>a&&b>c)
cout<<"\n"<<b;
else
cout<<"\n"<<c;
getch();
}
OUTPUT
/*PROGRAME TO CONVERT THE LOWER CASE TO UPPER CASE.*/

#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void main()
{
clrscr();
char ch,c;
cout<<"\n enter any charecter=";
cin>>(ch);
if(islower(ch))
{
c=toupper(ch);
cout<<"\n the charecter in upper case="<<c;
}
else
cout<<"\n it is already in upper case";
getch();
}
OUTPUT
/*PROGRAME TO COUNT NUMBER OF SPACE IN STRING*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[80];
int i,count=0;
cout<<"Enter any string: "<<"\n";
gets(str);
for(i=0;str[i]!='\0';i++)
if(str[i]==' ')
count++;
cout<<"number of spaces in the given string are: "<<count;
getch();
}

OUTPUT
/*PROGRAME TO COUNT THE NUMBER OF VOWELS*/
#include<conio.h>

#include<stdio.h>

void main()

clrscr();

char line[80];

int vow=0;

cout<<"Enter the line: "<<"\n";

gets(line);

for(int i=0;line[i]!='\0';i++)

switch(line[i])

case'a':

case'A':

case'e':

case'E':

case'i':

case'I':

case'o':

case'O':

case'u':

case'U':

vow++;
}

cout<<"The total number of vowels in the given line is: "<<vow<<"\n";

getch();

OUTPUT
/*PROGRAME TO SEARCH ANY ELEMENT IN THE ARRAY*/
#include<iostream.h>

#include<conio.h>

void main()
{
clrscr();
int a[50],i,num,n,c=0,pos;
cout<<"\nenter the size of matrix=";
cin>>n;
cout<<"\nenter the element in the array=";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\nenter the number to be search=";
cin>>num;
for(i=0;i<n;i++)
{
if(a[i]==num)
{
c=1;
pos=i+1;
break;
}
}
if(c==0)
cout<<"\nnmber not found=";
else
cout<<num<<" is found at the position "<<pos;
getch();
}
OUTPUT
/*PROGRAME TO SUM OF TWO MATRIX*/

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],b[3][3],c[3][3],i,j;
cout<<"\nenter the number in metrix A=";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>a[i][j];
}
cout<<"\nenter the numberin matrix B=";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>b[i][j];
}
cout<<"\n sum of matrix";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
c[i][j]=a[i][j]+b[i][j];
}
for(i=0;i<3;i++)
{ cout<<"\n";
for(j=0;j<3;j++)
cout<<c[i][j]<<"\t";
}
getch();
}
OUTPUT
/*PROGRAME TO CHECK WHETHER MATRICES ARE EQUAL OR NOT*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[50][50],b[50][50],c,d;
cout<<"enter the size of matrixes=";
cin>>c>>d;
cout<<"enter the element of first matrix=";
for(int i=0;i<c;i++)
{
for(int j=0;j<d;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
cout<<"enter the element of second matrix=";
for(int k=0;k<c;k++)
{
for(int l=0;l<d;l++)
{
cin>>b[k][l];
}
cout<<"\n";
}
int f=0;
for(int x=0;x<c;x++)
{
for(int y=0;y<d;y++)
{
if(a[x][y]!=b[x][y])
{
f=1;
break;
}
}
if(f==1)
break;
}
if(f==1)
cout<<"matrices are not equal";
else
if(f==0)
cout<<"matrices are equal";
getch();
}
OUTPUT
/*PROGRAME TO DIAGONAL SUM OF MATRIX (RIGHT, LEFT)*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20][20],sum1=0,sum2=0,m,k,i,j;
cout<<"\nenter the size of the matrix=";
cin>>m>>k;
cout<<"\nenter the element in the matrix=";
for(i=0;i<m;i++)
{
for(j=0;j<k;j++)
cin>>a[j][i];
}
for(i=0;i<m;i++)
{
for(j=0;j<k;j++)
{
if(i==j)
sum1+=a[i][j];
if(i+j==(m-1))
sum2+=a[i][j];
}
}
cout<<"\ndiagonal sum of matrix(right)="<<sum1;
cout<<"\ndiagonal sum of matrix(left)="<<sum2;
getch(); }
OUTPUT
/*PROGRAME TO DISPLAY THE LOWER AND UPPER HALF
MATRIX.*/
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void main()
{
clrscr();
int i,j,a[20][20],n,m;
cout<<"\nenter the size of matrix=";
cin>>n;
cout<<"\nenter the element in matrix=";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"\nTHE LOWER HALF MATRIX";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<=i;j++)
cout<<"\t"<<a[i][j];
}
cout<<"\n";
cout<<"\nTHE UPPER HALF MATRIX";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=i;j<n;j++)
cout<<"\t"<<a[i][j];
cout<<"\n";
}
getch();
}
OUTPUT
/*PROGRAME TO FIND THE NUMBER OF ‘T’ AND ‘t’ FROM THE
STRING.*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[50];
int i,c1=0,c2=0;
cout<<"\nenter any string=";
gets(a);
{
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='T')
c1++;
if(a[i]=='t')
c2++;
}
}
cout<<"\nnumber of T in string="<<c1;
cout<<"\nnumber of t in string="<<c2;
getcch();
}
OUTPUT
\*PROGRAME TO SWAP ARRAY*\
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a[5],i,t,j=4;
for(i=0;i<5;i++)
cin>>a[i];
for(i=0;i<5/2;i++)
{
t=a[i];
a[i]=a[j];
a[j]=t;
j--;
}
for(i=0;i<5;i++)
cout<<a[i]<<"\t";
getch();
}
OUTPUT
/*PROGRAME TO CHECK THE NUMBER IS PELINDROM OR NOT
AND REVERSE THE ENTER NUMBER.*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long int n,num,d,r=0;
cout<<"\nenter any number=";
cin>>num;
n=num;
do
{
d=num%10;
r=(r*10)+d;
num=num/10;
}
while(num!=0);
cout<<"\nthe reverse number is";
if(n==r)
cout<<" palindram";
else
cout<<" not palindrom";
cout<<"\n reverse of given number:"<<r;
getch();
}
OUTPUT
/*PROGRAME TO FIND THE FACTOR OF GIVEN NUMBER WITH THE
HELP OF FUNCTION NAME FACT() WITHOUT PARAMETER.*/
#include<iostream.h>
#include<conio.h>
#include<math.h>
void fact()
{
int a,i,j;
cout<<"\nenter a positive integer=";
cin>>a;
cout<<"\nfactors of "<<a<<" are";
for(i=a;i>=1;i--)
{
if(a%i==0)
cout<<"\n"<<i;
}
}
void main()
{
clrscr();
fact();
getch();
}
OUTPUT
/*PROGRAME TO PRINT TABLES FROM 2 TO 10 WITH THE HELP OF
FUCTION NAME TABLE FUNCTION SHOULD BE NON
RETURNABLE.*/

#include<iostream.h>
#include<conio.h>
void table()
{
int i,j;
for(i=1;i<=10;i++)
{
cout<<"\n";
for(j=2;j<=10;j++)
cout<<"\t"<<i*j;
}
}
void main()
{
clrscr();
table();
getch();
}
OUTPUT
/*PROGRAME TO SHOW CUBE OF A NUMBER WITH HELP OF
FUNCTION*/
#include<iostream.h>

#include<conio.h>

void cube(int x)

int z;

z=x*x*x;

cout<<z;

void main()

clrscr();

int a;

cout<<"\nenter any number=";

cin>>a;

cube(a);

getch();

OUTPUT
\* PROGRAME TO CALCULATE AREA OF TRIANGLE,AREA OF
SQUARE AND AND AREA OF RECTANGLE*\
#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

clrscr();

int y,z,a,ch;

cout<<"\t\t\t\t\t calculation";

cout<<"\n\t\t\t\t\t 1.area of triangle";

cout<<"\n\t\t\t\t\t 2.area of square";

cout<<"\n\t\t\t\t\t 3.arae of rectangle";

cout<<"\n enter two elements=";

cin>>y>>z;

cout<<"\n enter choice for calculator=";

cin>>ch;

if (ch==1)

a=(y*z)/2;

else

if (ch==2)

a=y*y;

else

if (ch==3)

a=y*z;
else

cout<<"\ wrong choice="<<ch;

cout<<"\n result="<<a;

getch();}

OUTPUT
\* PROGRAME TO FIND THE SIMPLE INTEREST*\
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int p,r,t,si=0;
cout<<"\n enter the principal=";
cin>>p;
cout<<"\n enter the rate=";
cin>>r;
cout<<"\n enter the time=";
cin>>t;
si=(p*r*t)/100;
cout<<"\n simple interest="<<si;
getch();
}
OUTPUT
\* PROGRAME TO FIND THE SUM OF NATURAL NUMBERS FROM 1
TO 100*\
#include<iostream.h>
#include<conio.h>
void main()
{
int sum;
clrscr();
for(int i=1;i<=100;i++)
sum+=i;
cout<<"\n sum="<<sum;
getch();
}
OUTPUT
/*PROGRAME TO CHECK NUMBER IS PRIME OR NOT*/

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int n,i,c=0;
cout<<"\nenter any number=";
cin>>n;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
c++;
}
}
if(c==2)
cout<<n<<" is a prime number";
else
cout<<n<<" is not a prime number";
getch();
}
OUTPUT
/*PROGRAME TO ENTER MARKS OF 5 SUBJECT OF 3 STUDENTS
DISPLAY NAME, MARKS OF 5 SUBJECT TOTAL
PERCENTAGE,GRADE.*/

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[3][20];
int sub[5][3],i,j;
float per=0.0;
for(i=0;i<3;i++)
{
int sum=0;
cout<<"\n\nSTUDENT NAME=";
gets(a[i]);
cout<<"MARK OF FIVE SUBJECT OUT OF 100=";
for(j=0;j<5;j++)
{
cin>>sub[j][i];
sum+=sub[j][i];
}
per=(sum/5);
cout<<"\nsum of mark="<<sum;
cout<<"\npercentage="<<per;
if(per>=75)
cout<<"\ngrade A+";
else
if(per>=60 && per<75)
cout<<"\ngrade A";
else
if(per>=50 && per<60)
cout<<"\ngrade B";
else
if(per>=40 && per<50)
cout<<"\ngrade C";
else
if(per>=33 && per<40)
cout<<"\ngrade D";
else
if(per<30)
cout<<"\ngrade E";
}
getch();
}
OUTPUT
\*PROGRAME OF LEAP YEAR WITH THE HELP OF FUNCTION*\

#include<iostream.h>
#include<conio.h>
void leap(int);
void main()
{
clrscr();
int a,e;
cout<<"\n Enter The Any Year=";
cin>>a;
leap(a);
getch();
}
void leap(int x)
{
if(x%4==0)
cout<<"\n Yes,It is a Leap Year";
else
cout<<"\n No,It is not a Leap Year";
}
OUTPUT
/*PROGRAME TO ENTER ANY CHARECTER AND DISPLAY THE
NEXT CHARECTER.*/

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char a,b;
cout<<"\n enter any letter=";
cin>>a;
b=a+1;
cout<<"\n the next letter is="<<b;
getch();
}
OUTPUT
/*PROGRAME TO ARRENGE THE ARREY IN ASCENDING AND
DESCENDING ORDER.*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"\n enter the couting of number=";
cin>>n;
int i,a[100],b,j;
cout<<"\n enter the numbers=";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n data before arranging=";
for(j=0;j<n;j++)
{
cout<<"\t"<<a[j];
}
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
b=a[j];
a[j]=a[j+1];
a[j+1]=b;
}
}
}
cout<<"\ndata in ascending order= ";
for(j=0;j<n;j++)
{
cout<<a[j]<<"\t";
}
cout<<"\ndata in descending order= ";
for(j=n-1;j>=0;j--)
{
cout<<a[j]<<"\t";
}
getch();}
OUTPUT
/*PROGRAME TO COMPARE THE STRING*/
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char a[50],b[50];
cout<<"\nenter two string:=";
gets(a);
gets(b);
if(strcmp(a,b)==0)
cout<<"\equal";
else
cout<<"\not equal";
getch();
}
OUTPUT
/*PROGRAME TO CONTENTMENT TWO STRINGS*/
#include<iostream.h>

#include<conio.h>

#include<string.h>

#include<stdio.h>

void main()

clrscr();

char str1[15]="TWO,ONE";

char str2[16]="FIVE,FOUR,THREE";

cout<<strcat(str2,str1);

getch();

OUTPUT
/*PROGRAME TO DISPLAY ELEMENTS OF MATRIX WHICH IS
DIVISIBLE BY 3&7 */
#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

clrscr();

int a[3][3],j,i;

cout<<"\n enter the values of a=";

for (i=0;i<3;i++)

for(j=0;j<3;j++)

cin>>a[i][j];

cout<<"\n element which is divisible by 3 and 7 both";

for (i=0;i<3;i++)

for(j=0;j<3;j++)

if(a[i][j]%3==0&&a[i][j]%7==0)

cout<<a[i][j]<<"\n";

getch(); }
OUTPUT
/* PROGRAME PRINT THE PATTERN OF STARS USING FOR LOOP */
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

for(int i=1;i<=5;i++)

cout<<"\n"<<”\n<<”\n;

for(int j=1;j<=i;j++)

cout<<"\*"<<”\t”;

getch();

OUTPUT
\* PROGRAME TO ENTER THE DETAILS OF AN EMPLOYEE*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct employee
{
char nm[20];
int en;
char add[30];
float s;
};
void main()
{
clrscr();
employee a[3];
int i;
for(i=0;i<3;i++)
{
cout<<"\n enter name of employee=";
gets(a[i].nm);
cout<<"\n employee no=";
cin>>a[i].en;
cout<<"\n enter address=";
gets(a[i].add);
cout<<"\n enter salary=";
cin>>a[i].s;
}
cout<<"\n output:";
for(i=0;i<3;i++)
cout<<"\n name="<<a[i].nm<<"\nemployee no="<<a[i].en<<"\n address="<<a[i].add<<"\n
salary="<<a[i].s;
cout<<"\n---------------------*-------------";
getch();
}
OUTPUT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy