You are on page 1of 4

1.

Write a program that reads a list of a 10


numbers from the keyboard & output the
following:
a. Find and print the sum and average of all
integer.
b. Find and print the sum and average of all
positive integer.
c. Find and print the largest and smallest
number.
d. Count the number between 30 and 90.
#include<iostream.h>
#include<conio.h>
#include<math.h>
main()
{
int n, i, L, S,count=0,nu=0,de=0,summ=0,a1,b1,c1,c2,d;
float ave, a2,b2;
cout<<"INPUT 10-DIGIT NUMBER:"<<endl;
cin>>n;
summ+=n;
if(n>=0)
{
nu+=n;
de++;

if(n>=30 && n<=90)


count++;
if (n<S)
S=n;
if (n>L)
L=n;
}
ave=(float)nu/de;
a1=summ;
a2=(float)summ/10;
b1=nu;
b2=ave;
c1=L;
c2=S;
d=count;
cout<<"A.Sum of all Integers="<<a1<<endl;
cout<<"A.Ave of all Integers="<<a2<<endl;
cout<<"B.Sum of all positive integer="<<b1<<endl;
cout<<"B.Ave of all positive integer ="<<b2<<endl;
cout<<"C.Largest="<<c1<<endl;
cout<<"C.Smallest="<<c2<<endl;
cout<<"D.Count="<<d<<endl;
getch();
}

if(n>=30 && n<=90)


count++;
n=L; n=S;
for(i=1;i<=9;i++)
{
cin>>n;
summ+=n;
if(n>=0)
{
nu+=n;
de++;
}

2. Write a program that will compute the factor of


non-negative number.

#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;

for(y=n, z = 0; (y*z) >=0 , z<=10; y+=0, z++)


cout<<y<<"x"<<z<<"="<<(y*z)<<endl;

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();
}

You might also like