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

University of Agriculture Faisalabad T.T Singh: Introducton To Programming Assignment No. 1&2 1 Semmester CS - 303

This document contains assignments and programs submitted by a student named Hafiz Muhammad Talha for their Introduction to Programming course. It includes 5 programs for Assignment 1 and 5 programs for Assignment 2, along with the code and output for each program. The programs cover topics like grading systems, finding the largest/smallest number, character ASCII values, patterns, and calculating electricity bills.

Uploaded by

Talha Umar Sial
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)
33 views

University of Agriculture Faisalabad T.T Singh: Introducton To Programming Assignment No. 1&2 1 Semmester CS - 303

This document contains assignments and programs submitted by a student named Hafiz Muhammad Talha for their Introduction to Programming course. It includes 5 programs for Assignment 1 and 5 programs for Assignment 2, along with the code and output for each program. The programs cover topics like grading systems, finding the largest/smallest number, character ASCII values, patterns, and calculating electricity bills.

Uploaded by

Talha Umar Sial
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/ 14

UNIVERSITY OF AGRICULTURE FAISALABAD

T.T SINGH

INTRODUCTON TO PROGRAMMING

ASSIGNMENT NO. 1&2

1ST SEMMESTER

CS_303

HAFIZ MUHAMMAD TALHA UAMR

2015-ag-7968
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
Second number is the square of fiest number
Code:
#include<iostream>
using namespace std;
void main()
{
int a,b;
cout<<"enter the number 2"<<endl;
cin>>a>>b;
if(a*a==b)
{
cout<<"second no. is the square of first number"<<endl;
}

system("pause");

output
Bill
#include<iostream>
using namespace std;
void main()
{
int units;
float bill;

cout<<"ENTER THE UNITS="<<endl;


cin>>units;

if(units<=300)
{bill= units*2;}
else if(units<=500)
{bill= units*5;}
else
{bill= units*7;}
bill=bill+150;
if(bill>2000)
{bill=bill+(bill*5/100);}
cout<<bill<<"bill is:";

system("pause");

}
THE END

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