Posts

Showing posts from October, 2015

Given a sentence in a form of a string, reverse string in this manner...for e.g. string is " please keep smile " then reverse is "smile keep please"

#include<stdio.h> void word(char *ptr,int n) {     int  j;     char c;  for(j=0;j<n/2;j++)  {     c=ptr[j];     ptr[j]=ptr[n-j-1];     ptr[n-j-1]=c;  } } void strev(char *tpr,int i) {     word(tpr,i);     int k=0,j;     for(j=0;j<=i;j++)     {         if(tpr[j]==' ' || tpr[j]=='\0')         {             word(tpr+k,j-k);         }          if(tpr[j]==32)         {             k=j+1;         }     } } int main() { char str[100]; int l=0; printf("enter string\n"); gets(str); while(str[l]!='\0')     {         l++;     } strev(str,l); printf("%s",str); return 0; }

program for enter your full name and then name is seprate according first,middle and last name

#include<stdio.h> void seprate(char a[],char b[],char c[],char d[]) {    static int i=0;    int j=0,k=0,l=0,s=0;       while(a[l]!='\0')       {           if((a[l]==' ' && a[l+1]!=' ')||l==strlen(a)-1)           {               s++;           }           l++;       }   while(1)   {       if(a[i]==32)       {           break;       }      b[i]=a[i];      i++;   }   while(a[i]==32) {    i++; } if(s==3) {   while(1)   {        if(a[i]==32)        {            break;        }     c[j]=a[i];     i++;     j++;   } } if(s==2||s==3) { while(a[i]==32)   {    i++;   }   while(1)   {     if(a[i]=='\0')     {         break;     }     d[k]=a[i];     i++;     k++;   } }   return ; } void main() {  char a[50],b[50]=" ",c[50]=" ",d[50]=" ",o[50];  printf("\n enter your full name");  gets(a);

rotated 3*3 metrix 90 degree clock wise

#include<stdio.h> void main() {    int a[3][3],i,j,t,s;    printf("enter element in 3*3 metrix");    for(i=0;i<3;i++)    {      for(j=0;j<3;j++)      {        scanf("%d",&a[i][j]);      }    }    printf("your metrix is");    for(i=0;i<3;i++)    {      for(j=0;j<3;j++)      {        printf("\t %d",a[i][j]);      }      printf("\n");    }     for(i=0;i<3;i++)    {      for(j=3;j>=i;j--)       {           t=a[i][j];           a[i][j]=a[j][i];           a[j][i]=t;       }      printf("\n");    }     for(i=0;i<3;i++)    {      for(j=0;j==0;j++)       {           t=a[i][j];           a[i][j]=a[i][j+2];           a[i][j+2]=t;       }      printf("\n");    }   printf("aftr 90 degree clock wise ");     printf("\n");     for(i=0;i<3;i++)    {      for(j=0;j<3;j++)      {        printf("\t %d",a[i][j]);      }      printf("\n");    } }

transpose n*n metrix without using extra array

#include<stdio.h> void main() {    int a[4][4],i,j,t,s;    printf("enter 4*4 metrix");    for(i=0;i<4;i++)    {      for(j=0;j<4;j++)      {        scanf("%d",&a[i][j]);      }    }    for(i=0;i<4;i++)    {      for(j=0;j<4;j++)      {        printf("\t %d",a[i][j]);      }      printf("\n");    }     printf("\n");     for(i=0;i<4;i++)    {      for(j=3;j>=i;j--)       {           t=a[i][j];           a[i][j]=a[j][i];           a[j][i]=t;       }      printf("\n");    }     for(i=0;i<4;i++)    {      for(j=3;j>=i;j--)       {           t=a[i][j];           a[i][j]=a[j][i];           a[j][i]=t;       }      printf("\n");    }     for(i=0;i<4;i++)    {      for(j=0;j<4;j++)      {        printf("\t %d",a[i][j]);      }      printf("\n");    } }

mid sem c practical lab nitk b3 batch qstn 1

#include<stdio.h> void main() {  int array[10];  int n,i,j,temp;  printf("\n enter the no of element you want to insert");  scanf("%d",&n);  printf("\n enter the element");  for(i=0;i<n;i++)  {     scanf("%d",&array[i]);  }  for(i=0;i<n;i++)  {    for(j=1;j<n-i;j++)    {      if(array[i]>array[i+j])      {      temp=array[i];      array[i]=array[i+j];      array[i+j]=temp;   }    }  }  i=0;  printf("array[i]+array[j]=%d",array[i]+array[i+1]); }