assignement of c++

15
Assignment No.1 Submitted To: Adnan Nawaz Submitted By: Syed Muhammad Umair Shah Subject: Introduction to Programming Department: Computer Science Roll No. 12 Indus International Institute D.G.Khan

Upload: syed-umair

Post on 15-Jul-2015

17 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Assignement of c++

Assignment No.1Submitted To: Adnan Nawaz

Submitted By: Syed Muhammad Umair Shah

Subject: Introduction to Programming

Department: Computer Science

Roll No. 12

Indus International Institute D.G.Khan

Page 2: Assignement of c++

/*Write a program that generates the following output using a single nested loop$##$$$#### */#include<iostream.h>#include<conio.h>void main(){clrscr();int i,j;for(i=1;i<=4;i++){

for(j=1;j<=i;j++)if(i%2==0)cout<<"#";elsecout<<"$";cout<<"\n";}

getch();}

Output

Page 3: Assignement of c++

/*Show 1st 8 FIBONACCI Number */#include<iostream.h>#include<conio.h>void main(){clrscr();long int a=21,b=0,c=1,sum;while(b<a){cout<<c<<" ";sum=b+c;b=c;c=sum;}getch();}

Output

Page 4: Assignement of c++

/*Write a program that input two number interchange the value of and then display them without using third variable.*/#include<iostream.h>#include<conio.h>void main() { clrscr(); int a,b;cout<<"Entr 1st num : ";cin>>a;cout<<"Entr 2nd num : ";cin>>b;cout<<"Value Befor Swapping:"<<endl;cout<<"1st num="<<a<<endl;cout<<"2nd num="<<b<<endl;a=a+b;b=a-b;a=a-b;cout<<"Value After Swapping:"<<endl;cout<<"1st num="<<a<<endl;cout<<"2nd num="<<b<<endl;getch();}

Output

Page 5: Assignement of c++

/*Show out********** */#include<iostream.h>#include<conio.h>void main(){clrscr();int i,j;for(i=1;i<=4;i++){for(j=i;j<=4;j++){cout<<"*";}cout<<"\n";}getch();}

Output

Page 6: Assignement of c++

/*Triangle */#include<iostream.h>#include<conio.h>void main() //if(i==1&&i==4&&j==1&&j==x){clrscr();int i,j,sp,x=1;for(i=1;i<=4;i++,x=x+2){for(sp=1;sp<=4-i;sp++) cout<<" ";for(j=1;j<=x;j++){if(i>1&&i<4&&j>1&&j<x)cout<<" ";elsecout<<"*";}cout<<"\n";}getch();}

Output

Page 7: Assignement of c++

/*Take input of Three n.o if the are not Equal,then find the Smallest n.o*/#include<iostream.h>#include<conio.h>void main(){clrscr();int a,b,c;cout<<"Entr 1st n.o = ";cin>>a;cout<<"Entr 2nd n.o = ";cin>>b;cout<<"Entr 3rd n.o = ";cin>>c;if((a<b)&&(a<c))cout<<"Smallest n.o is = "<<a;else if((c<a) && (c<b)){cout<<"Smallest n.o is = "<<c;}

else if((b<a) && (b<c)){cout<<"Smallest n.o is = "<<b;}else{cout<<"All n.o are Equal";}getch();}

Output

Page 8: Assignement of c++

/*Take input of two n.o if 2nd n.o is greater than 1st,display the divisionas follow i.e. 1st=16 2nd=5 Ans=5*3+1=16*/#include<iostream.h>#include<conio.h>void main(){clrscr();int n1,n2;cout<<"Entr 1st no. = ";cin>>n1;cout<<"Entr 2nd no. = " ;cin>>n2;if(n2>n1){cout<<"invalide input";}elsecout<<n2<<" * "<<n1/n2<<" + "<<n1%n2<<" = "<<n1<<"\n";getch();}

Output

Page 9: Assignement of c++

/*Show out*************** */#include<iostream.h>#include<conio.h>void main(){clrscr();int i,j;for(i=1;i<=3;i++){for(j=1;j<=5;j++){cout<<"*";}cout<<"\n";}getch();}

Output

Page 10: Assignement of c++

/* Show out*

*****

**** */#include<iostream.h>#include<conio.h>void main(){clrscr();int i,j,sp;for(i=1;i<=4;i++){for(sp=1;sp<=4-i;sp++){cout<<" ";}

for(j=1;j<=i;j++){cout<<"*";}cout<<"\n";}

getch();}

Output

Page 11: Assignement of c++

/*Take input a n.o and find if it is divisible by 10 or not*/#include<iostream.h>#include<conio.h>void main(){clrscr();int a;cout<<"Entr any number = ";cin>>a;if(a%10==0){cout<<"it is Divisible by 10";}else{cout<<"it is not Divisible by 10";}getch();}

Output

Page 12: Assignement of c++

/* d=++a + a-- - b++ + --c = 1*/#include<iostream.h>#include<conio.h>void main(){clrscr();int a=2,b=4,c=0,d;d=++a + a-- - b++ + --c;cout<<d;getch();}

Output

Page 13: Assignement of c++

/*SUM OF 1ST 6TH PRIME NUMBER*/#include<iostream.h>#include<conio.h>void main(){clrscr();

int i,j,sum=0,flag=1,x;//outer Loop

for(i=1,x=0;x<=5;i++){//inner Loop

for(j=2;j<=i/2;j++){

if(i%j==0){

flag=0;break;

}}

if(flag){

x++;sum+=i;cout<<i<<" + ";}

else{

flag=1;}}cout<<"\b\b = "<<sum;getch();}

Output

Page 14: Assignement of c++

/*entr 10 student age and show average age*/#include <iostream.h>#include<conio.h>void main(){clrscr();float age1,age2,age3,age4,age5,age6,age7,age8,age9,age10;float TotalAge;float AverageAge;cout <<" Please Enter The Age Of Student 1:" ;cin >> age1;cout <<" Please Enter The Age Of Student 2:" ;cin >> age2;cout <<" Please Enter The Age Of Student 3:" ;cin >> age3;cout <<" Please Enter The Age Of Student 4:" ;cin >> age4;cout <<" Please Enter The Age Of Student 5:" ;cin >> age5;cout <<" Please Enter The Age Of Student 6:" ;cin >> age6;cout <<" Please Enter The Age Of Student 7:" ;cin >> age7;

cout <<" Please Enter The Age Of Student 8:" ;cin >> age8;cout <<" Please Enter The Age Of Student 9:" ;cin >> age9;cout <<" Please Enter The Age Of Student 10:" ;cin >> age10;TotalAge=age1+age2+age3+age4+age5+age6+age7+age8+age9+age10;AverageAge=TotalAge/10 ;cout << " Average Age Of Class Is : " << AverageAge ;getch();}

Output

Page 15: Assignement of c++

/*Enter The Amount Of The Bill And Discount At The Rate Of 10% */#include <iostream.h>#include<conio.h>void main (){clrscr();double amount,discount,netpayable;

cout << " Please Enter The Amount Of The Bill ";cin >> amount;

if(amount>5000){discount = amount*(15.0/100);netpayable = amount-discount;cout <<" The Discount At The Rate Of 15 % is Rupees " << discount << endl;cout << " The Payable Amount is Rupees " << netpayable;}else{discount = amount*(10.0/100);

netpayable = amount-discount;cout <<" The Discount At The Rate Of 10 % is Rupees " << discount << endl;cout << " The Payable Amount is Rupees " << netpayable;}getch();}

Output