Showing posts with label C Programme. Show all posts
Showing posts with label C Programme. Show all posts

C Programme to print all the numbers and sum of all the integers that are greater then 100 and less than 200 and are divisible by 7.


#include<stdio.h>

#include<conio.h>



int main()

{

            int i,sum=0;

            clrscr();



            for(i=100;i<200;i++)

            {

                        if(i%7==0)

                        {

                                    printf(" %d ",i);

                                    sum=sum+i;

                        }

            }



            printf("\n\n Sum of all above integers that are divisible by 7 is  %d",sum);



            getch();



            return 0;

}





Output:

C Programme to print the triangle.

            a  b  c  d  e
              a  b  c  d
                a  b  c
                  a  b
                    a

#include<stdio.h>

#include<conio.h>



int main()

{

            int i,n,j,k;

            clrscr();



            printf("Enter  the number : ");

            scanf("%d",&n);

            printf("\n");

            for(i=0;i<n;i++)

            {

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

                        {

                                    printf(" ");

                        }

                        for(j=1;j<=n-i;j++)

                        {

                                    printf(" %c",96+j);

                        }

                        printf("\n");

            }



            getch();



return 0;

}                                                                                                                    



Output:

C Programme to print series 2, 4, 16,……,n*n using shorthand operator and while loop.

Print series 2, 4, 16,……,n*n using shorthand operator and while loop.


#include<stdio.h>
#include<conio.h>

int main()
{
            int n,x;  // declare the variable
            long double i=2;  //declare the variable of long double type
            clrscr(); 

            printf("Enter the number : ");
            scanf("%d",&n);

            printf("\n");

            x=1;
            while(x<=n)   //  loop will be execute till the value of x I less or equal n
            {
                        printf("%.2Lf\n",i);  // print the value of I upto 2 decimals only
                        x++;
                        i*=i;
            }

            getch();

            return 0;
}


Output:

C Programme program to print Name, Address and Birth Date.

program to print Name, Address and Birth Date.

#include<stdio.h>
#include<conio.h>

int main()
{
            clrscr();   //  clears the output window

            printf("\n Name : David");             // prints the name
            printf("\n Address : London");        // prints the address
            printf("\n Birth Date : 02-08-1958");    // prints the birth date

            getch();

            return 0;
}


Output:

C Programme to print “Hello World” message


program to print “Hello World” message.


#include<stdio.h>
#include<conio.h>

int main()
{
            clrscr();   // clears the output window

            printf("\n \"Hello World\"");    // prints the message

            getch();

            return 0;
}


Output:

C Programme to generate Fibonacci series

program to generate Fibonacci series.


#include<stdio.h>
#include<conio.h>

int main()
{
            int n1=0,n2=1,n3=1,n,i;
            clrscr();

            printf("Enter the Number : ");
            scanf("%d",&n);

            printf("\n");
            for(i=1;i<=n;i++)
            {
                        printf(" %d ",n3);
                        n3=n1+n2;
                        n1=n2;
                        n2=n3;
            }
            getch();

            return 0;
}


Output:

C Programme to find the roots of an equation ax2 + bx + c = 0

program to find the roots of an equation ax2 + bx + c = 0.


#include<stdio.h>
#include<conio.h>
#include<math.h>

int main()
{
            float a,b,c,alf,bt,dlt;
            clrscr();

            printf("\n Enter a: ");
            scanf("%f",&a);

            printf("\n Enter b: ");
            scanf("%f",&b);

            printf("\n Enter c: ");
            scanf("%f",&c);

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

            if(dlt==0)
            {
                        printf("\n ALPHA=BETA=%f",-b/(2*a));
            }
            else if(dlt<0)
            {
                        printf("\n Imaginary Roots");
            }
            else
            {
                        alf=(-b+sqrt(dlt))/(2*a);
                        bt=(-b-sqrt(dlt))/(2*a);
                        printf("\n\n Alpha = %f\n Beta=%f\n",alf,bt);
            }

            getch();

            return 0;
}







Output:

C Programme to print series 2, 4, 6, 8,…....,n.

Print series 2, 4, 6, 8,…....,n.



#include<stdio.h>
#include<conio.h>

int main()
{
            int i,n;  // declare two integer type variables
            clrscr();  // clears the output window

            printf("\n Enter the number : ");
            scanf("%d",&n);  // input the value of n

            printf(“\n”);   // will break the line on output window

            for(i=2;i<=n;i++)
            {
                        if(i%2==0)
                        {          
                                    printf(" %d ",i);
                        }
            }

            getch();

            return 0;
}


Output:

C Programme to print size of int, float, double variable.

program to print size of int, float, double variable.
#include<stdio.h>
#include<conio.h>

int main()
{
            clrscr();

            printf("Size of int is -> %d\n",sizeof(int));

            printf("Size of long is -> %d\n",sizeof(float));

            printf("Size of double is -> %d\n",sizeof(double));

            getch();

            return 0;
}



Output:

C Programme program to sort given array in ascending order.

program to sort given array in ascending order.

#include<stdio.h>
#include<conio.h>

int main()
{
            int a[20],i,j,n,temp;
            clrscr();

            printf("\n Enter no. of elements for 1-D array : ");
            scanf("%d",&n);

            for(i=0;i<n;i++)
            {
                        printf(" Enter element[%d] : ",i+1);
                        scanf("%d",&a[i]);
            }

            for(i=0;i<n;i++)
            {
              for(j=i+1;j<n;j++)
              {
                        if(a[i]>a[j])
                        {
                                    temp=a[i];
                                    a[i]=a[j];
                                    a[j]=temp;
                        }
              }
            }

            printf("\n\n Ascending order of inserted  array is : ");
            for(i=0;i<n;i++)
            {
                        printf("\n %d ",a[i]);
            }

            getch();
           
            return 0;
}





Output:

C Programme that prints the Floyd’s triangle

program that prints the following Floyd’s triangle.

    1
    2  3   
    4  5  6
    7  8  9  10
    11 ………..15
    .
    .
    79 …………………91