Showing posts with label Simple Programes (Beginers). Show all posts

Write a program to find GCD and LCM in C++ language

#include <iostream>
using namespace std;

int main()
{
    int a, b, temp, gcd, lcm, x, y;
    cout << "Enter two number: ";
    cin >> x>>y;
   
    a = x;
    b = y;
   
    while(b!= 0)
    {
           temp = b;
           b = a%b;
           a = temp;
    }
   
    gcd = a;
    lcm = x*y/gcd;
   
    cout << "GCD is: "<<gcd<<"\nLCM is: "<<lcm<<endl;
    system("pause");
}

Write a program in C++ to find angle between minutes and second hand, hour and second hand and hour and minute hand.

#include <iostream>
using namespace std;

int main()
{
    int hour, minut, second, angle1, angle2, angle;
    cout << "Enter hour: ";
    cin >> hour;
    cout << "Enter minut: ";
    cin >> minut;
    cout << "Enter second: ";
    cin >> second;
   
    //angle between hour and minut.
    if(angle1 == 12)
    angle1 = 0;
   
    angle1 = hour*30;
    angle2 = minut*6;
 
    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and minut is: ";
    cout << angle << endl;
   
    //angle between hour and second.
    if(angle1 == 12)
    angle1 = 0;
   
    angle1 = hour*30;
    angle2 = second*6;

    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and second is: ";
    cout << angle << endl;
   
    //angle between hour and second.
    angle1 = minut*6;
    angle2 = second*6;

    angle = angle2 - angle1;
    if(angle < 0)
    {
         angle1 = 360 - angle1;
         angle = angle1 + angle2;
    }
    cout << "Angle between hour and second is: ";
    cout << angle << endl;
   
    cout <<endl;
    system("pause");
}

Write a program to add two numbers by using pointers in C++ language.

#include <iostream>
using namespace std;

int main()
{
    int a, b, *p1, *p2, sum;
    cout << "Enter both numbers: ";
    cin >> a >> b;
    p1 = &a;
    p2 = &b;
    sum = *p1 + *p2;
    cout << "Sum is " << sum <<endl;
    system("pause");
}

Write a program to swap numbers using two variables.

#include <stdio.h>
#include <conio.h>
main()
{
      int a, b;
      printf("Enter To Numbers: ");
      scanf("%d%d", &a, &b);
      //swaping
      a=a+b;
      b=a-b;
      a=a-b;
      printf("%d %d", a, b);
      getch();
}

Write a program to print ASCCI code for given character.

#include<stdio.h>
#include<conio.h>
int main()
{
   char ch;
   printf("Enter a chararcter: ");
   ch=getche();

   printf("\nThe ASCII Code for \%c is %d",ch,ch);
   getch();
}

Write a program to calculate volum and area of sphere.

#include<stdio.h>
#include<conio.h>
int main()
{
    float r,v,area;
    printf("Enter the radius of the sphere\n ");
    scanf("%f", &r);
    area=4*3.14*r*r*r;
    v=(4/3.14)*3.14*r*r*r;
    printf("volume of the sphere=%f\n", v);
    printf("area of sphere=%f\n", area);
    getch();
    }

Write a program to find the area of sphere


#include<stdio.h>
#include<conio.h>
int main()
{
    float r,v,area;
    printf("Enter the radius of the sphere\n ");
    scanf("%f",&r);
    area=4*3.14*r*r*r;
    v=(4/3.14)*3.14*r*r*r;
    printf("volume of the sphere=%f\n", v);
    printf("area of sphere=%f\n",area);
    getch();
    
    }

Write a program to calculate and print circumference of a circle


#include<stdio.h>
#include<conio.h>
int main()
{
float circumference,pie,r;
pie=3.14;
r=5;
circumference=2*pie*r;
printf("print the circumference of circle");
printf(" circumference is %f",circumference);
getch();
}

Write a program to print your name in a stylish format.

Note: This program is compiled in Turbo C. 

 #include <stdio.h>
   #include <conio.h>
   #include <dos.h>
   int a;
   void main ()
   {
      clrscr();
      for(a=1; a<29; a++)
      {
      gotoxy(a,13); //goto coordinates (x, y) and print
      delay(100); //stay for a moment
      textcolor(a);
      cprintf(" allclanguageprograms.blogspot.com");
      }
      for(a=65; a>27; a--)
      {
      gotoxy(a,13); //goto coordinates (x, y) and print
      delay(50); //stay for a moment
      textcolor(a);
      cprintf("allclanguageprograms.blogspot.com");
      }
      getch();
   }