C ++ Program Solutions :

  C++ solutions :

//This is the program for show F :

Ques # 1

#include<iostream>

using namespace std;

 int main()

 {

 

float f = 5.00F; cout << f;

}

Q # 2:

for this patteren ://4 7 10 13 16...

#include<iostream>

using namespace std ;

 int main()

 {

  //4 7 10 13 16 19 22.. also you can 

  int a=2;

  for (a=2;a<=20;a++)

  {

  a=a+2;//<<endl;

  cout<<a<<endl;

}

cout<<endl;


Ques # 3 :

for show the ans is 0

int i=4,j=1;

for(i=0;j>i;j--)

{

cout<<j-1<<endl;

}

return 0;

 }

Question #4 :

for show the ans is 24:

#include<iostream>

using namespace std; 

 int main()

 {

  int x=1;

  while(++x<=5)

  {

  cout<<x<<"";

  x++;

}

return 0;

 }

Question # 5:

#include<iostream>

using namespace std ;

 int main()

 {

  system ("color 02");

  for(int i=2;i<=2048;i=i+i)

  {

  cout<<i<<endl;

}


 

 

  return 0;

 

 }

 

 

 #include<iostream>

using namespace std;

 int main()

 {

  int num1,num2;

  cout<<"enter the num 1 :";

  cin>>num1;

  cout<<"enter the num2 :";

  cin>>num2;

  cout<<"the sum of num1 and num2 :"<<num1+num2<<endl;

  return 0;

 }

 

 

 

 #include <iostream>

using namespace std;


int main()

{

    // declare variables

    int var1 = 3;

    int var2 = 24;

    int var3 = 17;

    int *a=&var1;

    int *b=&var2;

    int *c=&var3;


    // print address of var1

    cout << "Address of var1: "<< &var1 << endl;

cout<<"value at variable 1 :"<<*a<<endl;

    // print address of var2

    cout << "Address of var2: " << &var2 << endl;

    cout<<"value at variable 2 :"<<*b<<endl;


    // print address of var3

    cout << "Address of var3: " << &var3 << endl;

    cout<<"value at variable 3 :"<<*c<<endl;

}




#include <iostream>

using namespace std;


int main()

{

    float arr[3];


    // declare pointer variable

    float *ptr;

    

    cout << "Displaying address using arrays: " << endl;


    // use for loop to print addresses of all array elements

    for (int i = 0; i < 3; ++i)

    {

        cout << "&arr[" << i << "] = " << &arr[i] << endl;

    }


    // ptr = &arr[0]

    ptr = arr;


    cout<<"\nDisplaying address using pointers: "<< endl;


    // use for loop to print addresses of all array elements

    // using pointer notation

    for (int i = 0; i < 3; ++i)

    {

        cout << "ptr + " << i << " = "<< ptr + i << endl;

    }


    return 0;

}



#include<iostream>

using namespace std;

int main()

{

// system("color 02");

int marks []={24,34,45,67,34};

cout<<marks[0]<<endl;

cout<<marks[1]<<endl;

cout<<marks[2]<<endl;

cout<<marks[3]<<endl;

cout<<marks[4]<<endl;

for(int i=0;i<=4;i++)

{

cout<<"the value of marks is :"<<i<<"\tis"<<marks[i]<<endl;

};

cout<<"\nwe can wright also :"<<endl;

int mathmarks[4];//={56,56,34,56,34};

mathmarks[0]=56;

mathmarks[1]=65;

mathmarks[2]=65;

mathmarks[3]=34;

mathmarks[2]=78;// we can change after this wright

for(int i=0;i<=4;i++)

{

cout<<"the value of mathmarks is :"<<i<<"\tis"<<mathmarks[i]<<endl;

}

cout<<mathmarks[0]<<endl;

cout<<mathmarks[1]<<endl;

cout<<mathmarks[2]<<endl;

cout<<mathmarks[3]<<endl;

//cout<<mathmarks[4]=34<<endl;

//cout<<marks[5]<<endl;

//pointers and arrays :

cout<<"\n\n\n"<<endl;

cout<<"THIS IS ALL FOR POINTERS AND ARRAYS :"<<endl;

int *p=marks;

cout<<*(p++)<<endl;

cout<<*(p++)<<endl;

cout<<*(p++)<<endl;

cout<<*(p++)<<endl;

cout<<*(p++)<<endl;

//another method is that

// cout<<"the value at p on marks :"<<*p<<endl;

// cout<<"the value at p on marks :"<<*(p+1)<<endl;

// cout<<"the value at p on marks :"<<*(p+2)<<endl;

// cout<<"the value at p on marks :"<<*(p+3)<<endl;

return 0;

}


#include<iostream>

using namespace std;

 int main()

  {

 

        cout<<"this is the Arthimatic operator :"<<endl;

  int a=4,b=5;

  cout<<"the value if  a and b :"<<a+b<<endl;

      cout<<"the value if  a and b :"<<a-b<<endl;

      cout<<"the value if  a and b :"<<a*b<<endl;

      cout<<"the value if  a and b :"<<a/b<<endl;

      cout<<"the value if  a and b :"<<a%b<<endl;

      cout<<"the value if  a and b :"<<a++<<endl;

                   

      cout<<"the value if  a and b :"<<a--<<endl;

          cout<<"the value if  a and b :"<<++a<<endl;

              cout<<"the value if  a and b :"<<--a<<endl;

              

              

      cout<<"this is the comparison operator :"<<endl;

      

             cout<<"the value if  a and b :"<<(a==b)<<endl;

cout<<"the value if  a and b :"<<(a!=b)<<endl;

cout<<"the value if  a and b :"<<(a<=b)<<endl;

cout<<"the value if  a and b :"<<(a>=b)<<endl;

cout<<"the value if  a and b :"<<(a>b)<<endl;

cout<<"the value if  a and b :"<<(a<b)<<endl;

// cout<<"the value if  a and b :"<<a+b<<endl;

// cout<<"the value if  a and b :"<<a+b<<endl; 


        cout<<"this is the logical operator :"<<endl;

        

        cout<<"the logical and operator is ((a==b)&&(a<b)) :"<<((a==b) && (a<b))<<endl;

        cout<<"the logical or operator is ((a==b)||(a<b)) :"<<((a==b) || (a<b))<<endl;

        cout<<"the logical not operator is (!(a==b):"<<(!(a==b))<<endl;

                   

            return 0;                        

 }

 

 

 

 #include<iostream>

using namespace std;

int main()

{

/*the ASCII CHAR IN BINARY IS */

system("color 02");

cout<<"enetr any char :"<<endl;

char a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

cin>>a>>b>>c>>d>>e>>f>>g>>h>>i>>j>>k>>l>>m>>n>>o>>p>>q>>r>>s>>t>>u>>v>>w>>x>>y>>z;

cout<<"\nthe ASCII value of char is "<<int(a)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(b)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(c)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(d)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(e)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(f)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(g)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(h)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(i)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(j)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(k)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(l)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(m)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(n)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(o)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(p)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(q)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(r)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(s)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(t)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(u)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(v)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(w)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(x)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(y)<<"\n";

cout<<"\nthe ASCII value of char is "<<int(z)<<"\n";

return 0;

}


/*wright the program to get three float num from user and get their assending order :*/

#include<iostream>

using namespace std;

int main()

{

x: system ("color 02");

float a,b,c;

cout<<"\tenter teh num :";

cin>>a;//<<endl;

cout<<"\tenter teh num :";

cin>>b;//;<<endl;

cout<<"\tenter teh num :";

cin>>c;//;<<endl;

if(b<a && a<c)

{

cout<<"Assending order is "<<b<<" "<<a<<" "<<c<<endl;

}

else if(a<b && b<c)

{

cout<<"Assending order is "<<a<<" "<<b<<" "<<c<<endl;

}

else if(c<a && a<b)

{

cout<<"Assending order is "<<c<<" "<<a<<" "<<b<<endl;

}



else if(c<b && b<a)

{

cout<<"Assending order is "<<c<<" "<<b<<" "<<a<<endl;

}


else if(b<c && c<a)

{

cout<<"Assending order is "<<b<<" "<<c<<" "<<a<<endl;

}


goto x;






return 0;

}



#include<iostream>

#include<stdlib.h>

using namespace std ;

int main()

{

/*GENERATE RANDOM NUM*/

system ("color 02");

int i,num;

cout<<"\nGENERATE RANDOM NUMBERS :"<<endl;

for(i=1;i<=10;i++)

{

num=rand()%100;

scout<<"\n"<<num<<"\n";

}

cout<<"\n"<<endl;

}


#include<iostream>

using namespace std ;

 int main()

 {

  system("color 02");

  int a,b,c;

 x: cout<<"enter the num "<<endl;

  cin>>a;

    cout<<"enter the num "<<endl;

  cin>>b;

    cout<<"enter the num "<<endl;

  cin>>c;

  if(a>b && a>c)

  {

  cout<<"\na is greater :"<<endl;

 

  }

   else if (b>a && b>c)

  {

  cout<<"b is greater :"<<endl;

  }

  else

{

cout<<"c is greater :"<<endl;

}

 goto x;

  return 0;

   

   

 }

 

 #include <iostream>

using namespace std;


int main() {

    int n;

    long double factorial = 1.0;


    cout << "Enter a positive integer: ";

    cin >> n;


    if (n < 0)

        cout << "Error! Factorial of a negative number doesn't exist.";

    else {

        for(int i = 1; i <= n; ++i) {

            factorial *= i;

        }

        cout << "Factorial of " << n << " = " << factorial;    

    }


    return 0;

}




/*Check even and odd program */

#include<iostream>

using namespace std;

int main()

{

/*check two num is even or odd*/

int num,i;

cout<<"entr a num to check the even or odd :"<<endl;

cin>>num>>i;

if(num%2==0)

{

cout<<"\nthe num is even :";

}

else 

{

cout<<"num is odd :"<<endl;

}


   if  (num&1==0)

{

cout<<"\nthe num is odd :"<<endl;

//

}

else {

cout<<"\nthis num will be  is even :"<<endl;

}


return 0;

//

//

//

//

}



//Simple escape sequences

//\' single quote byte 0x27 in ASCII encoding

//\" double quote byte 0x22 in ASCII encoding

//\? question mark byte 0x3f in ASCII encoding

//\\ backslash byte 0x5c in ASCII encoding

//\a audible bell byte 0x07 in ASCII encoding

//\b backspace byte 0x08 in ASCII encoding

//\f form feed - new page byte 0x0c in ASCII encoding

//\n line feed - new line byte 0x0a in ASCII encoding

//\r carriage return byte 0x0d in ASCII encoding

//\t horizontal tab byte 0x09 in ASCII encoding

//\v vertical tab byte 0x0b in ASCII encoding

//Numeric escape sequences

//\nnn arbitrary octal value byte nnn

//\xnn arbitrary hexadecimal value byte nn

//Conditional escape sequences[1]

//\c Implementation-defined Implementation-defined

//Universal character names

//\unnnn arbitrary Unicode value;

//may result in several code units code point U+nnnn

//\Unnnnnnnn arbitrary Unicode value;

//may result in several code units code point U+nnnnnnnn


#include<iostream>

using namespace std;

int main()

{

// int num;

// cout<<"enter num :";

// cin>>num;

// if(!(num<=0 || num >=5))

// {

// cout<<"num found :";

// }

// else

// {

// cout<<"num not found :"<<endl;

// }

// return 0;

//}


//bool flagT,flagF;

//flagT=true;

//flagF=false;

//

//if(!(!flagF && !flagT) || (!flagF && flagT))

//{

// cout<<"&&";

// cout<<"##";

//

//}

//return 0;

//

//int marks =80;

//if(marks>=90)

//{

// cout<<"excellence rerult:"<<endl;

//}

//

//if(marks>=80)

//{

// cout<<"very good rerult:"<<endl;

//}

//if(marks>=70)

//{

// cout<<"good rerult:"<<endl;

//}

//if(marks>=65)

//{

// cout<<"saticifiocation rerult:"<<endl;

//}

//else 

//{

// cout<<"unsatisfy :"<<endl;

//}

//return 0;




}


#include<iostream>

using namespace std ;

int main()

{

system("color 02");

int d,w,y;

cout<<"\nenter the days :";

cin>>d;

y=d/365;

d=d%365;

w=d/7;

d=d%7;

cout<<"the numbers of years in these days :"<<y<<endl;

 //    cout<<"the numbers of years in these days :"<<<<endl;

     cout<<"the numbers of weeks in these days :"<<w<<endl;

     cout<<"the numbers of days in these days :"<<d<<endl;

     return 0;

}



#include<iostream>

using namespace std;

 int main()

// {  /*wright a program that show all the num that is divisible by 3;  by using while loop*/

// int i=1;

// while(i<=1000)

// {

// if(i%3==0)

// {

// cout<<i<<endl;

// }

//  

// i++;

// }

// return 0;

// }

// {

// 

// int i=1;

//while(i<=1000)

//{

// if(i%3==0)

// {

// cout<<i<<endl;

// }

// i++;

//}

//return 0;

//}

//again practice 

{

int i =1;

while(i<=1000)

{

if(i%3==0)

{

cout<<i<<endl;

}

i++;

}

return 0;

}


//calculate the num of gallons 

#include<iostream>

using namespace std ;

 int main()

 {

  int a=12,b=350;

  float f;

  cout<<"\n the num of galonns is :"<<a<<endl;

  cout<<"the cars travels the distance 350 miles :"<<b<<endl;

  f=b/a;

     cout<<"the distance is :"<<f<<endl;

     return 0;

 }

 

 /*write a program that takes three distincts inputs from user 

and dsplay the second smallest of them*/


#include<iostream>

using namespace std; 

int main()

{

int a,b,c;

cout<<"enetr the numbers :"<<endl;

cin>>a>>b>>c;

     if(a<b && a>c || a>b && a<c)

     {

      cout<<"the second smallest num is :"<<a<<endl;

     }

     if(b<a && b>c || b>a && b<c )

     {

      cout<<"the secnd smallest num is :"<<b<<endl;

     }

     if(c<a && c>b || c>a && c<b)

     {

      cout<<"the second smallest num is :"<<c<<endl;

     }

return 0;

}


#include<iostream>

using namespace std; 

int main()

{

int a=2,b=2,c;

//2 4 6 10 16 26 48 ..

for(int i=1;i<=11;i++)

{

cout<<a<<" "<<endl;

c=a+b;

b=a;

a=c;

}

return 0;

}


#include<iostream>

using namespace std;

 void positive()


 {

 x:

  bool positive;

int num;

  cout<<"enter a num :"<<endl;

  cin>>num;

  cout<<endl;

  if(num>0)

  {

  cout<<"num is positive :"<<endl;

}

else 

{

positive=false;

cout<<"IT IS FALSE :"<<endl;

}

goto x;

 

 }

 

 int main()

 {

 

 positive();

 return 0;

}

 

 

 #include<iostream>

using namespace std;

 int main()

 {

 x: int n;

  cout<<"enter any num :";

  cin>>n;

  //for(int i=2;i<=n;)

  //{int 

int i=2;

  if(n%i==0)

  {

  cout<<"\nit not prime number :"<<endl;

}

else {

cout<<"\nprime num"<<endl;

}

goto x;  

// }

return 0;

 }

 

 //pattren

#include<iostream>

using namespace std;

int main()

{

// for(int j=20;j>=0;j=j-2)

// {

// cout<<"\t";

// cout<<j;

// }

for(int j=2;j<=228;j=j+4)

{

cout<<"\t";

cout<<j;

}

return 0;

 } 

 

 

 /*program give warning the value of the temeprature is grater than 100 otherwise ok*/

#include<iostream>

using namespace std ;

int main()

{

// int tem,n,p;

// cout<<"enter the temeprature :"<<endl;

// cin>>tem;

// if(tem>=100 || p>=200 )

// {

// cout<<"warning";

// }

// else 

// {

// cout<<"its fine ok";

// }


int num;

cout<<"enter the odd num :";//odd num 

cin>>num;

for(int i=1;i<=num;i=i+2)

{

cout<<i<<endl;

}


return 0;

}


#include<iostream>

#include<math.h>

using namespace std;

 int main()

 {

  system("color 02");

  float n,sq;

  cout<<"enter a num for sqrt :"<<endl;

  cin>>n;

 

  sq=sqrt(n);

  cout<<"\nthe squrt is :"<<sq;

 

 

  cout<<"\nTHIS PROGRAM IS FOR THE MULTIPLE WITH POWER :"<<endl;

 

  int num,x;

  cout<<"\nenter a num for :"<<endl;

  cin>>num;

 cout<<"\nenter a num for power :"<<endl;

  cin>>x;

  int result;

  result=pow(num,x);

 

  cout<<"the mul of power is :"<<result;


 

 

 

 

  return 0;

 }

 

 #include<iostream>

using namespace std;

int main()

{

cout<<"\nSELECTION CONTROL STRUCTURE USING IF ELSE and Else IF LADDER  :";

system ("color 02");

// cout<<"this is tutorial 9 :";

// cout<<"if else and switch case :"<<endl;

int age;

cout<<"enter your age :";

cin>>age;

// if((age<18) && (age>2))

// {

// cout<<"you cannot come to the party  :";

//

// }

// else if(age==18)

// {

// cout<<"you are kid and enjoy your life with kids :";

//

// }

// else if(age<2)

// {

// cout<<"you are not yet born :";

// }

// else

// {

// cout<<"you can come to teh party :"<<endl;

// }

cout<<"SWITCH CASE USED IN SELETION CONTROL STRUCTURE :";

switch(age)

{

case 18:

cout<<"you are 18:"<<endl;

break;

      case 22:

      cout<<"you are 22"<<endl;

      break;

case 2:

cout<<"you are 2 :"<<endl;

break;

default:

cout<<"no special cases :";

break;

}

return 0;

}



#include<iostream>

using namespace std;

int main()

{

system("color 02");

int num,mul;

cout<<"\n\nenter a num :"<<endl;

cin>>num;

//mul=1;

for(mul=1;mul<=10;mul++)

{

cout<<num<<"*"<<mul<<"="<<(num*mul)<<endl;

//mul++;

}//while(mul<=10);

return 0;

}




#include <iostream>

#include <cmath>

using namespace std;


int main() {


    float a, b, c, x1, x2, discriminant, realPart, imaginaryPart;

    cout << "Enter coefficients a, b and c: ";

    cin >> a >> b >> c;

    discriminant = b*b - 4*a*c;

    

    if (discriminant > 0) {

        x1 = (-b + sqrt(discriminant)) / (2*a);

        x2 = (-b - sqrt(discriminant)) / (2*a);

        cout << "Roots are real and different." << endl;

        cout << "x1 = " << x1 << endl;

        cout << "x2 = " << x2 << endl;

    }

    

    else if (discriminant == 0) {

        cout << "Roots are real and same." << endl;

        x1 = -b/(2*a);

        cout << "x1 = x2 =" << x1 << endl;

    }


    else {

        realPart = -b/(2*a);

        imaginaryPart =sqrt(-discriminant)/(2*a);

        cout << "Roots are complex and different."  << endl;

        cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;

        cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;

    }


    return 0;

}



// sum o fist any num 

#include<iostream>

using namespace std;

 int main()

 {

  int n,sum;

  cout<<"enter teh num :"<<endl;

  cin>>n;

 

  for(int i=1;i<=n;i++)

  {

 

  sum =sum+i//for add all numbers;

 }

 cout<<endl;

 cout<<"the sum is :"<<n<<"sum of series is :"<<sum<<endl;

 return 0;

 }

 

 

 #include <iostream>

using namespace std;


int main() {

    int n, sum = 0;


    cout << "Enter a positive integer: ";

    cin >> n;


    for (int i = 1; i <= n; ++i) {

        sum += i;

    }


    cout << "Sum = " << sum;

    return 0;

}



#include<iostream>

using namespace std;

int main()

{

int a,b;

cout<<"Before swapping values is :"<<endl;

cout<<"enter a num for a:"<<endl;

cin>>a;

cout<<"enter 2nd num for b:"<<endl;

cin>>b;

cout<<"\nBefore swapping values is :"<<endl;

a=a+b;

b=a-b;

a=a-b;

cout<<"\nafetr swapping the value of a is:"<<a<<"\nafter swapping the value of b is\nand "<<b;

cout<<"\nafter swapping :"<<endl;

return 0;

}


IN THIS PROGRAMS YOU CAN FIND OUT YOUR PROGRAMS SOLUTINS 

NOW ON NEXT PAGE YOU WILL SEE 2 PROJECTS OF C++ :







    

    






0 Comments

Post a Comment