Sunday, 3 July 2016

More Problems

Write a program that does the following.The program asks the user to enter a positive integer n.  The program prints a triangle with n rows using the number r to make the characters on row number r. For example, if the user enters 4 for n the output is as follows:
1
22
333
4444

 Code:- 

/*program to make triangle with n rows using the number r to make the
characters on row number r. */
#include<iostream>
using namespace std;
int main()
{
       int n,r,a,b=1;
       cout<<"Enter positive Integer= ";
       cin>>a;
       for(n=0;n<a;n++)
       {
              for(r=0;r<=n;r++)
              {
                     cout<<b;
              }
              cout<<endl;
              b=b+1;
       }
       system("pause");
       return 0;
}
Write a program that prompts the user to input an integer then outputs both the individual digits and the sum of the digits..????
//program to seperate number into its digits and sum of digits.

#include<iostream>
using namespace std;
int main()
{

       int a,b,c,sum=0;
       cout<<"Enter Number"<<endl;
       cin>>a;
       do
       {
              b=a%10;
              c=a/10;
              cout<<b<<" ";
              sum=sum+b;
              a=c;
       }
       while(a!=0);
       cout<<endl;
       cout<<"Sum of Digits= "<<sum<<endl;
       system("pause");
       return 0;
}
Write a program that ask user to input 10 integers and then print the sum of the even and odd integers using loop statements......??????

//program to put ten integer and then sum of the even and odd integers,

#include<iostream>

using namespace std;

int main()

{

       int i,n,Sumeven=0,Sumodd=0;
       cout<<"Enter Ten Numbers:"<<endl;
       for(i=0;i<10;i++)
       {
              cout<<"Enter Number:"<<endl;
              cin>>n;
              if (n%2==0)
              {
              Sumeven=Sumeven+n;
              }
              else if (n%2==1)
              {
                     Sumodd=Sumodd+n;
              }
       }
       cout<<"Sum of even numbers="<<Sumeven<<endl;
       cout<<"Sum of odd numbers="<<Sumodd<<endl;
       system("pause");
       return 0;

}
Input a number from the user and display if the number is a prime number or not...?????

//program to show whether no is prime or not.

#include<iostream>

using namespace std;

int main()

{

       int a,i,flag=0;
       cout <<"Enter positive Integer"<<endl;
       cin>>a;
       for (i=2; i<a; i++)
       {
              if (a%i==0)
              {
                     flag++;
              }
       }
       if (flag==0)
       cout <<"Prime number"<<endl;
       else
              cout<<"Not Prime number"<<endl;
       system("pause");
       return 0;

}
Input four numbers and display the numbers in ascending and descending order......???????????
//program to arrange four numbers in ascending and descending order
#include<iostream>
using namespace std;
int main()
{
       int a,b,c,d,s,t,x,y;
       cout<<"Enter Four Numbers"<<endl;
       cin>>a>>b>>c>>d;
       if(a<b) x=b, y=a;
       else if(b<a) x=a, y=b;
       if(a>b) s=a, t=b;
       else if(b>a) s=a, t=b;
       if(x<c) y=x, x=c;
       else if(y<c) y=c;
       if(s>c) t=s, s=c;
       else if(t>c) t=c;
       if(x<d) y=x, x=d;
       else if(y<d) y=d;
       if(s>d) t=s, s=d;
       else if(t>d) t=d;
       cout<<"Largest Number="<<x<<endl;
       cout<<"2nd Largest Number="<<y<<endl;
       cout<<"Smallest Number="<<s<<endl;
       cout<<"2nd smallest Number="<<t<<endl;
       cout<<"Numbers in ascending order"<<":"<<s<<"  "<<t<<"  "<<y<<"  "<<x<<endl;
       cout<<"Numbers in descending order"<<":"<<x<<"  "<<y<<"  "<<t<<"  "<<s<<endl;
       system("pause");
       return 0;
}
Input a number from the user if the number is divisible by 3 display ‘PADDLE’. If the
number is divisible by 5 display ‘POP’. If the number is divisible by 3 and 5 both display
‘PADDLEPOP’. Else display ‘Not divisible by 3 or 5’.....????????????


//program to display different words on different condition
#include<iostream>
using namespace std;
int main()
{
       int a,b,c,d,e;
       cout<<"Enter Number"<<endl;
       cin>>a;
       b=a%3;
       c=a%5;
       if (b==0)
              cout<<"PADDLE"<<endl;
       if (c==0)
              cout<<"POP"<<endl;
       if (c==0 && b==0)
              cout<<"PADDLEPOP"<<endl;
       if (c!=0 && b!=0)
              cout<<"Not divisible by 3or5"<<endl;
       system("pause");
       return 0;
}
Input five numbers from the user and display the largest and 2nd largest number..?????

//program to find largest number and second largest number from five numbers
#include<iostream>
using namespace std;
int main()
{
       int a,b,c,d,e,x,y;
       cout<<"Enter Five Numbers"<<endl;
       cin>>a>>b>>c>>d>>e;
       if(a<b) x=b, y=a;
       else if(b<a) x=a, y=b;
       if(x<c) y=x, x=c;
       else if(y<c) y=c;
       if(x<d) y=x, x=d;
       else if(y<d) y=d;
       if (x<e) y=x, x=e;
       else if(y<e) y=e;
       cout<<"Largest Number="<<x<<endl;
       cout<<"2nd Largest Number="<<y<<endl;
       system("pause");
       return 0;
}

No comments:

Post a Comment