Programs in Dev C++ loops
1: Write a program to print the following series using while loop.
100 10
90 40
80 70
70 100
#include<iostream>using namespace std;
int main()
{
int no1,no2;
no1=100;
no2=10;
while(no1>=70 && no2<=100)
{
cout<<no1<<"\t\t"<<no2<<"\n";
no1=no1-10;
no2=no2+30;
}
return 0;
}
2: Write a program input five value, compute the sum and average of input values using while loop. Also print the output of program on the screen.
#include<iostream>
using namespace std;
int main()
{
int n,sum,avg;
n=1,sum=0;
while(n<=5)
{
cout<<n<<"\n";
sum=sum+n;
n++;
}
cout<<"sum of number: "<<sum;
avg=sum/5;
cout<<"\n";
cout<<"Average: "<<avg;
return 0;
}
3: Write a program to calculate the sum of odd and even value of 1 to 10 numbers by using do-while loop statement.
#include<iostream>
using namespace std;
int main()
{
int n,sum;
n=1,sum=0;
cout<<"Even Number \n";
do
{
if(n%2==0)
{
cout<<n<<"\n";
sum=sum+n;
}
n++;
}while(n<=10);
cout<<"Sum: "<<sum;
cout<<"\n"<<endl;
n=1,sum=0;
cout<<"Odd Number \n";
do
{
if(n%2==1)
{
cout<<n<<"\n";
sum=sum+n;
}
n++;
}while(n<=10);
cout<<"Sum: "<<sum;
}
4: Write a program that print capital alphabet using for loop.
#include<iostream>
using namespace std;
int main()
{
char ch;
for(ch='A';ch<='Z';ch++)
{
cout<<ch;
cout<<"\n";
}
return 0;
}
5: Write a program to input a table and show their reverse order.
#include<iostream>
using namespace std;
int main()
{
int n,c;
cout<<"Enter Table Number";
cin>>n;
for(c=10;c>=1;c--)
{
cout<<n<<" * "<<c<<" = "<<n*c<<"\n";
}
return 0;
}
No comments:
Post a Comment