Professional Documents
Culture Documents
#include<iostream.h>
#include<conio.h>
main()
{
int n, x;
cout<<"Enter a non-negative integer: "<<endl;
cin>>n;
cout<<"The factors are: "<<endl;
for(x=1;x<=n;x++)
{
if(n%x==0)
cout<<x<<" ";
}
getch();
}
3. Write a program that will ask the user to input an
integer & will generate the multiplication table.
#include<iostream.h>
#include<conio.h>
main()
{
int n,y,z;
start:
cout<<"INPUT A NUMBER:"<<endl;
cin>>n;
cout<<y ;
cout<< " " ;
for(int i =0; i<(number-2); i++)
{
z = x+y;
cout << z << " ";
x=y;
y=z;
}
getch();
}
5. Write a program that will allow the user to input an
integer & output the floyds triangle.
#include<iostream.h>
#include<conio.h>
main()
{
int number,y,x,z;z=1;
cout<<"INPUT A NUMBER:"<<endl;
cin>>number;
system ("pause");
system ("cls");
goto start;
for(x=1;x<=number;x++)
{
for(y=1;y<=x;y++,z++)
cout<<z<<" ";
cout<<endl;
}
getch();
getch();
}
4. Write a program that will ask the user to input a
number (Integer) & output the Fibonacci sequence.
#include<iostream.h>
#include<conio.h>
main()
{
int x=0,y=1, z,number;
cout << "Enter the number of terms of Fibonacci
Sequence:";
cin >> number;
cout << endl;
cout<< x ;
cout<<" " ;
}
6.
#include<windows.h>
void gotoxy(int x,int y)
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_
HANDLE),coord);
}
#include<iostream.h>
#include<conio.h>
main()
{
int x,y,c,r,u,v;
char z,n,i;
//firstloop
c=0;r=0;
for(x=1;x<=5;x++)
{
gotoxy(c,r);
for(y=x;y<=5;y++)
{
cout<<x;
}
r++;
}
//secondloop
c=0;r=14;
gotoxy (c,r);
for(z='a',x=1;z<='e',x<=5;z++,x++)
{
cout<<z<<endl;
cout<<x<<endl;
}
//third loop
c=0;r=25;
for(x=1,y=1,z='A';x<=4,y<=4,z<='D';x++,y++,z++)
{
cout<<"&";
cout<<"#";
cout<<z;
}
//fourth loop
c=30;r=10;
for(x=1;x<=5;x++)
{
gotoxy(c,r);
for(y=x;y<=5;y++)
cout<<"*";
c++;r--;
}
//fifth loop
c=35;r=6;n='a';
for (x=1;x<=5;x++)
{
gotoxy(c,r);
for (y=1;y<=x;y++)
{
cout<<n;n++;
}
r++;
}
//sixth loop
c=30;r=11;
for(x=5;x>=1;x--)
{
gotoxy(c,r);
for(y=1;y<=x;y++)
cout<<x;
r++;c++;
}
//seventh loop
c=35;r=11;u=0;v=1;n='a';
for (x=5;x>0;x--)
{
gotoxy(35,r);
if(x%2==1)
{
for(y=x;y>0;y--)
{
cout<<v;
}
v++;
}
else
{
for(y=x;y>0;y--)
{
cout<<n;
}
n++;
}
r++;
}
//eight loop
c=78;r=20;n='p';
for (x=1;x<=5;x++)
{
gotoxy(c,r);
for (y=1;y<=x;y++)
{
cout<<n;n--;
}
r++;c--;
}
//nineth loop
c=73;r=0;
for(x=1;x<=6;x++)
{
gotoxy (c,r);
cout<<"*";
c++;
}
c=73;r=0;
for (x=1;x<=5;x++)
{
gotoxy (c,r);
cout<<"*";
r++;
}
c=73;r=4;
for(x=1;x<=6;x++)
{
gotoxy (c,r);
cout<<"*";
c++;
}
c=78;r=0;
for (x=1;x<=5;x++)
{
gotoxy (c,r);
cout<<"*";
r++;
}
//tenth loop
c=75;r=1;n='e';
for(x=1;x<=3;x++)
{
gotoxy(c,r);
for(y=1;y<=3;y++)
cout<<n;
r++;
}
getch();
}