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

Prac 1

The document contains multiple C++ programming exercises that demonstrate basic programming concepts such as variable swapping, number classification (positive, negative, zero), finding the greatest of three numbers, grade assignment based on marks, vowel detection, and various patterns using loops. Each practice section includes a code snippet that illustrates the specific functionality. Overall, the document serves as a collection of simple programming tasks for beginners.

Uploaded by

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

Prac 1

The document contains multiple C++ programming exercises that demonstrate basic programming concepts such as variable swapping, number classification (positive, negative, zero), finding the greatest of three numbers, grade assignment based on marks, vowel detection, and various patterns using loops. Each practice section includes a code snippet that illustrates the specific functionality. Overall, the document serves as a collection of simple programming tasks for beginners.

Uploaded by

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

Prac 1

#include <iostream>

#include<cmath>

using namespace std;

int main()

int a,b;

cout<<"enter values of a and b"<<endl;

cin>>a;

cin>>b;

a=a+b;

b=a-b;

a=a-b;

cout<<"after swaping"<<a<<b<<endl;

return 0;

PRAC 2
#include <iostream>

#include <cmath>

using namespace std;

int main()

{
int a;

cout<<"enter a num :"<<endl;

cin>>a;

if(a==0)

cout<<"the num is zero"<<endl;

else if(a>0)

cout<<"the num is positive"<<endl;

else if(a<0)

cout<<"the num is negative"<<endl;

return 0;

Prac 3
#include <iostream>

using namespace std;

int main()

int a,b,c;
cout<<"enter 3 numbers: "<<endl;

cin>>a>>b>>c;

if ((a>b)&&(a>c))

cout<<a<<" is greater"<<endl;

else if((b>a)&&(b>c))

cout<<b<< "is greater"<<endl;

else

cout<<c<< "is greater"<<endl;

return 0;

Prac 4
#include <iostream>

using namespace std;

#include <conio.h>

int main()

int marks;

char grade;
cout<<"enter the marks:"<<endl;

cin>>marks;

if(marks>=80)

grade='A';

else if(marks>=70)

grade='B';

else if(marks>=60)

grade='C';

else if(marks>=50)

grade='D';

else

grade='F';

cout<<"your grade is"<<grade;

Prac 5
#include <iostream>

using namespace std;

int main()

int a;

char ch;

cout<<"enter any alphabet:"<<endl;

cin>>ch;
switch(ch)

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

cout<<"the alphabet is vowel";

break;

default:

cout<<"the alphabet is constant";

return 0;

Prac 8
#include <iostream>
using namespace std;

int main()
{
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=5;b++)
{

cout<<"*";
}
cout<<endl;
}

return 0;
}

Prac 9
#include <iostream>

using namespace std;

int main()

int a,b;

for(a=1;a<=5;a++)

for(b=1;b<=a;b++)

{
cout<<b;

cout<<endl;

return 0;

Prac 10
#include <iostream>

using namespace std;

int main()

int a,b;

for(a=1;a<=5;a++)

for(b=1;b<=2*a-1;b++)

{
cout<<"*";

cout<<endl;

return 0;

Prac 11
#include <iostream>
using namespace std;
int main()
{

int i,j,k;
for(i=1;i<=5;i++)
{
for(j=5;j>i;j--)
{cout<<" ";
}
for(k=1;k<=i;k++)
{

cout<<"* ";
}
cout<<endl;
}

Prac 7
#include <iostream>
using namespace std;
int main()
{
int i,j,k=1;
cout<<"enter the numberfor factorial";

cin>>j;
for(i=1;i<=j;i++)
{
k=k*i;
}
cout<<k;
return 0;

You might also like