Translate

Labels

Showing posts with label PROGRAMS. Show all posts
Showing posts with label PROGRAMS. Show all posts

Sunday, 15 February 2015

SWAPPING TWO NUMBERS IN A SINGLE STATEMENT

C program to swap two numbers in a single statement.



main()
{
int a=10,b=20;
c=(a+b)-(b=a);
printf("The numbers are :%d %d ",a,b);
getch();
}

Sunday, 4 January 2015

NUMBER PATTERN_5

12345
2345
345
45
5







int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=i;j<=5;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

NUMBER PATTERN_4

12345
1234
123
12
1






int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

NUMBER PATTERN_3


PERFECT SQUARE


1   2   3   4   5   6   7   8   9   10
36  37  38  39  40  41  42  43  44  11
35  64  65  66  67  68  69  70  45  12
34  63  84  85  86  87  88  71  46  13
33  62  83  96  97  98  89  72  47  14
32  61  82  95  100 99  90  73  48  15
31  60  81  94  93  92  91  74  49  16
30  59  80  79  78  77  76  75  50  17
29  58  57  56  55  54  53  52  51  18
28  27  26  25  24  23  22  21  20  19





int main()
{
    int a[10][10]={0},i,j,low=0,top=9,n=1;
    for(i=0;i<5;i++,low++,top--)
    {
        for(j=low;j<=top;j++,n++)
            a[i][j]=n;
        for(j=low+1;j<=top;j++,n++)
            a[j][top]=n;
        for(j=top-1;j>=low;j--,n++)
            a[top][j]=n;
        for(j=top-1;j>low;j--,n++)
            a[j][low]=n;
    }
    printf("\t\t\t\tPerfect Square\n");
    for(i=0;i<10;i++)
    {
        printf("\n\n\t");
        for(j=0;j<10;j++)
        {
            printf("%6d",a[i][j]);
            delay(300);
        }
    }
    return 0;
}

Wednesday, 31 December 2014

NUMBER PATTER_2

        1
       232
      34543
     4567654
    567898765


main()
{
      int n, c, d, num = 1, space;
 
      scanf("%d",&n);
 
      space = n - 1;
 
      for ( d = 1 ; d <= n ; d++ )
      {
          num = d;
 
          for ( c = 1 ; c <= space ; c++ )
              printf(" ");
 
          space--;
 
          for ( c = 1 ; c <= d ; c++ )
          {
              printf("%d", num);
              num++;
          }
          num--;
          num--;
          for ( c = 1 ; c < d ; c++)
          {
              printf("%d", num);
              num--;
          }
          printf("\n");
 
      }
 
      return 0;
}

STAR AND ALPHABET PATTERN

main()

{ int n, c, k, space, count = 1; printf("Enter number of rows\n"); scanf("%d",&n); space = n; for ( c = 1 ; c <= n ; c++) { for( k = 1 ; k < space ; k++) printf(" "); for ( k = 1 ; k <= c ; k++) { printf("*"); if ( c > 1 && count < c) { printf("A"); count++; } } printf("\n"); space--; count = 1; } return 0; }

Saturday, 15 November 2014

C PROGRAM TO REVERSE A STRING

String reverse using strrev function





main()
{
    char str[50];
    char *rev;
    printf("Enter any string : ");
    scanf("%s",str);
    rev = strrev(str);
   
    printf("Reverse string is : %s",rev);
   
    return 0;
}

Friday, 2 August 2013

PROGRAM TO FIND GCD OF TWO INTEGERS

GCD
mian()
{
int a,b ;
printf("Enter two positive integers :\n");
scanf("%d%d",&a,&b);
printf("GCD of %d and %d is %d\n",a,b,gcd(a,b));
}
gcd(int a,int b)
{
if(a)
return(b?gcd(b,a%b):a);
else
return b;
}



OUTPUT
Enter two positive integers
24   36
GCD of 24 and 36 is 12

Saturday, 13 July 2013

PASSING 2-D ARRAY TO A FUNCTION

There are three ways in which we can pass a 2-D array to a function.these are illustrated in the following program.

main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9,8,7,6};
clrscr();
display(a,3,4);
show(a,3,4);
print(a,3,4);
}


Tuesday, 2 July 2013

GET IP ADDRESS USING C PROGRAM

#include<stdlib.h>
int main()
{
system("C:\\windows\\system32\\ipconfig");
return 0;
}

Friday, 21 June 2013

FIBONACCI SERIES USING ARRAYS

#include<stdio.h>
#include<conio.h>
main()
{
int a[30];
int x,n;
clrscr();
printf("Enter no.of times to print:");
scanf("%d",&n);
printf("\n FIBONACCI SERIES :");

Thursday, 20 June 2013

PROGRAM TO HIDE THE SYNTAX OF C

#define BEGIN main(){
#define END}
#define EQUAL ==
#define READ(N) scanf("%d",&N)
#define WRITELN(N) printf("%d\n",N)

Sunday, 16 June 2013

PROGRAM FOR SHUTDOWN TIMER

#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<stdlib.h>
void main()
{
int t,i,s;
clrscr();
printf("enter the time in sec:");
scanf("%d",&t);

PROGRAM TO INSERT AN ELEMENT IN AN ARRAY

#define MAX 10
main()
{
int a[MAX]={11,22,33,44,55,77,88};
int n,x;
printf("Enter an element to be inserted \n");
scanf("%d",&x);
printf("Enter the position at which\n");
printf("this element to be inserted \n");
scanf("%d",&n);
insert(a,x,n);
}

PROGRAM TO STORE A FLOAT VALUE IN THE MEMORY

#include<malloc.h>
main()
{
float *fp;
fp=(float*)malloc(sizeof(float));
/*Initialization of pointer variable*/

PROGRAM TO FIND INTEGRAL VALUE USING SIMPSON'S RULE

#define f(x) 1.0/(1+x*x)
main()
{
int n;
float simps(float,float,int)a,b;
printf("Enter the values of a,b and n\n");
scanf("%f%f%d",&a,&b,&n);
printf("Integral value of f(x) by simpson's 1/3 rule:%f\n",simps(a,b,n));
}

Saturday, 15 June 2013

PROGRAM TO FIND THE INTEGRAL VALUE USING TRAPEZOIDAL RULE

#define f(x) 1.0/(1+x*x)
main()
{
int n;
float a,b;
float trapz(float,float,int);
printf("Enter the values of a,b and n\n");
scanf("%f%f%d",&a,&b,&n);
printf("Integral value of f(x) by trapezoidal rule:%f\n",trapz(a,b,n));
}

Friday, 14 June 2013

PROGRAM TO FIND EXECUTION TIME OF A PROGRAM

#include<time.h>
main()
{
time_t t1,t2;
clock_t clock(void);
int i,x=0,y=10;
t1=clock();

PROGRAM TO CONVERT 2-D ARRAY TO 1-D ARRAY

#define MAXROW 3
#define MAXCOL 2
main()
{
int a[MAXROW][MAXCOL],B[MAXROW*MAXCOL];
INT I,J,K=0;
printf("Enter the matrix elements in row order\n ");
for(i=0;i<MAXROW;i++);
for(j=0;j<MAXCOL;j++);
{
scanf("%d",&a[i][j]);
b[k++]=a[i][j];
}

Thursday, 13 June 2013

PROGRAM TO SOLVE TOWER OF HANOI PROBLEM

main()
{
int source,destination,other,nodisks;
printf("Enter the number of disks:\n");
scanf("%d",&nodisks);
if(nodisks<1)
{
printf("Illegal input\n");
exit(1);
}
source=1;
other=2;
destination=3;