Vous êtes sur la page 1sur 12

UNIVERSITY OF AGRICULTURE FAISALABAD

T.T SINGH

INTRODUCTON TO PROGRAMMING

ASSIGNMENT NO. 1&2

1ST SEMMESTER

CS_303

SUBMITTED BY:

HAFIZ MUHAMMAD TALHA UAMR

2015-ag-7968

SUBMITTED TO:

SIR IFTIKHAR HUSSAIN


ASSIGNMENT
NO.1
1 .program for the grading of marks by ' if else statement '

#include<iostream>
using namespace std;
void main()
{
int marks;
cout<<"Enter Student Marks :";
cin>>marks;
if(marks>=90)
cout<<"Student have grade A"<<endl;
else if(marks>=80)
cout<<"Student have Grade B"<<endl;
else if(marks>=70)
cout<<"Student have Grade C"<<endl;
else if(marks>=60)
cout<<"Student have Grade D<<endl";
else if(marks>=50)
cout<<"Student have Grade E"<<endl;
else
cout<<"Fail"<<endl;
system("pause");
}

Output
2. Find the largest number using if statement

#include<iostream>
using namespace std;
void main()
{
Int n1, n2, n3;
cout << "Enter 1 numbers: ";
cin >> n1;
cout << "Enter 2 numbers: ";
cin >> n2;
cout << "Enter 3 numbers: ";
cin >> n3;

if(n1>=n2 && n1>=n3)


{cout << "Largest number: " << n1;}
if(n2>=n1 && n2>=n3)
{cout << "Largest number: " << n2;}
if(n3>=n1 && n3>=n2)
{cout << "Largest number: " << n3;}

system("pause");
}

output
3. Find the smallest number using if statement

#include<iostream>
using namespace std;
void main()
{
int n1,n2,n3;
cout<<"Enter 1 values"<<endl;
cin>>n1;
cout<<"Enter 2 values"<<endl;
cin>>n2;
cout<<"Enter 3 values"<<endl;
cin>>n3;
if(n1<n2 && n1<n3)
cout<<"smallest value is:"<<n1<<endl;;
if(n2<n1 && n2<n3)
cout<<"Smallest value is:"<<n2<<endl;
else
cout<<"smallest value is:"<<n3<<endl;

system("pause");
}

Output
4. Find the ASCII value of given character

#include<iostream>
using namespace std;
void main()
{
char ASCII;
cout << "Enter a character: ";
cin >> ASCII;
cout << "ASCII VALUEVALUE IS:" << (int)ASCII << endl;

system("pause");
}

OUTPUT
5. Find grade using ‘case statement’

#include<iostream>
using namespace std;
void main()
{
int marks;
char grade;

cout<<" Enter your Marks = ";


cin>>marks;

switch(marks/10)
{
case 10: grade='A';
break;

case 9: grade='A';
break;

case 8: grade='A';
break;

case 7 : grade='B';
break;

case 6: grade='C';
break;

case 5: grade='D';
break;

default : grade='F';
}

cout<<"Your Grade is = "<<grade<<endl;


system("pause");
}
ASIGNMENT
NO.2
1.PRINT
@
@@@
@@@@@
@@@@@@@
CODE:
#include<iostream>
using namespace std;
void main()
{

int min_star=1,p_height=4,p_space=p_height-1;
for( int i=0;i<p_height;i++)
{
for(int j=p_space;j>i;j--)
{cout<<" ";}
for(int k=0;k<min_star;k++)
{cout<<"@";}

min_star+=2;
cout<<endl;
}

system("pause");
}

OUTPUT
2. PRINT

1
21
321
4321
54321
CODE:
#include<iostream>
using namespace std;
void main()
{

{
int z=1,k,n=5;

for(int a=1;a<=n;a++)
{
for(int k=n-1;k>=a;k--)
{cout<<" ";}
for(int b=z;b>=1;b--)
{cout<<b;}

z++;
cout<<endl;
}
}
system("pause");}
OUTPUT
3.PRINT A DIAMOND
CODE:
#include<iostream>
usingnamespacestd;
int main()
{
for(int a=0;a<1;a++)
{cout<<" *";}
cout<<endl;
for(int i=2;i<=3;i++)
{cout<<" ";
for(int j=i;j<3;j++)
{cout<<" ";}
for(int k=0;k<=i-1;k++)
{cout<<"* ";}
if(i==3)
{cout<<"* ";}
cout<<" ";
cout<<endl;
}
for(int i=2;i>=1;i--)
{cout<<" ";
for(int j=3;j>i;j--)
{cout<<" ";}
for(int k=i;k>=1;k--)
{cout<<" *";}
cout<<endl;
}
system("pause")
}

OUTPUT
THE END

Vous aimerez peut-être aussi