Assignment No.1
Submitted To: Adnan Nawaz
Submitted By: Syed Muhammad Umair
Subject: Programming &Problem Solving
Department: Computer Science
Semester: 2nd
Roll No. 12
Indus International Institute D.G.Khan
/*Write a program that generates the following output using a single nested loop
$
##
$$$
#### */
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
inti,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
if(i%2==0)
cout<<"#";
else
cout<<"$";
cout<<"n";
}
getch();}
Output:
/*Show 1st 8 FIBONACCI Number */
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
longint a=21,b=0,c=1,sum;
while(b<a)
{
cout<<c<<" ";
sum=b+c;
b=c;
c=sum;
}
getch();
}
Output:
/*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();
inta,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:

Assignment c++12

  • 1.
    Assignment No.1 Submitted To:Adnan Nawaz Submitted By: Syed Muhammad Umair Subject: Programming &Problem Solving Department: Computer Science Semester: 2nd Roll No. 12 Indus International Institute D.G.Khan
  • 2.
    /*Write a programthat generates the following output using a single nested loop $ ## $$$ #### */ #include<iostream.h> #include<conio.h> void main() { clrscr(); inti,j; for(i=1;i<=4;i++) { for(j=1;j<=i;j++) if(i%2==0) cout<<"#"; else cout<<"$"; cout<<"n"; } getch();} Output:
  • 3.
    /*Show 1st 8FIBONACCI Number */ #include<iostream.h> #include<conio.h> void main() { clrscr(); longint a=21,b=0,c=1,sum; while(b<a) { cout<<c<<" "; sum=b+c; b=c; c=sum; } getch(); } Output:
  • 4.
    /*Write a programthat input two number interchange the value of and then display them without using third variable.*/ #include<iostream.h> #include<conio.h> void main() { clrscr(); inta,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: