c++ lab sheet kuppiya- 6

24. Write a program that inputs five numbers and determines and prints the number of negative numbers input, the number of positive numbers input and the number of zeros input.

#include <iostream.h>

int main()
{
int a,b,c,d,e,tn,tz,tp;
tn=0;
tz=0;
tp=0;
cout<<“Enter Number: “;
cin>>a;
cout<<“Enter Number: “;
cin>>b;
cout<<“Enter Number: “;
cin>>c;
cout<<“Enter Number: “;
cin>>d;
cout<<“Enter Number: “;
cin>>e;
cout<<“”<<endl;
if(a<0)
(tn=tn+1);
else if(a==0)
(tz=tz+1);
else
(tp=tp+1);
if(b<0)
(tn=tn+1);
else if(b==0)
(tz=tz+1);
else
(tp=tp+1);
if(c<0)
(tn=tn+1);
else if(c==0)
(tz=tz+1);
else
(tp=tp+1);
if(d<0)
(tn=tn+1);
else if(d==0)
(tz=tz+1);
else
(tp=tp+1);
if(e<0)
(tn=tn+1);
else if(e==0)
(tz=tz+1);
else
(tp=tp+1);
cout<<“The number of negative numbers input: “<<tn<<endl;
cout<<“The number of positive numbers input: “<<tp<<endl;
cout<<“the number of zeros input: “<<tz<<endl;

return 0;
}

25.write an application that calculates the squares and cubes of the numbers from 0 to 10 and prints the resulting values in table format as follows:

#include <iostream.h>

int main()
{
int a;
a=0;
cout<<“Number”<<” “<<“Square”<<” “<<“Cube”<<endl;
while(a<=10)
{
cout<<a<<” “<<a*a<<” “<<a*a*a<<endl;
a++;
}

return 0;
}

26.Write an application that keeps displaying in the command window the multiples of the integer 2, namely 2, 4, 8, 16, 32, 64, etc up to 10000.

#include <iostream.h>

int main()
{
int a;
a=2;
while(a<=10000)
{
cout<<a<<endl;
a=a*2;
}

return 0;
}

27. Write an application that reads three nonzero values entered by the and determines and prints if they could represent the sides of a triangle.

28.Write a program to print the first 7 positive integers and their factorials. (The factorial of 1 is 1, the factorial of 2 is 1 * 2 = 2, the factorial of 3 is 1 * 2 * 3 = 6, the factorial of 4 is 1 * 2 * 3 * 4 = 24, etc.)

#include <iostream.h>

int main()
{
int a,f;
a=1;
f=1;
while(a<=7)
{
cout<<“Integer : “<<a<<endl;
f=a*f;
cout<<“factorial of “<<a<<” : “<<f<<“\n”<<endl;
a++;
}

return 0;
}

29.Write a program to find the average length of words in a sentence. Words are separated by a space. The sentence is terminated by a dot ( . )

30.Write a program to enter 10 numbers (maximum 10) but you should be able to stop if you enter a value less than 1. At the end you should be able to display whether you have entered 10 numbers or not.

#include <iostream.h>

int main()
{
int x,y,z;
y=1;
while(x>0&&y!=11)
{
cout<<“Enter Number: “;
cin>>x;
y+1;
cout<<x<<endl;
y++;

}
if(x<1)
cout<<“You have not entered 10 numbers”<<endl;
else
cout<<“You have entered 10 numbers”<<endl;

return 0;
}

Please comment .Thanks