Showing posts with label Swap. Show all posts
Showing posts with label Swap. Show all posts

C Program to Calculate Grid Size, Initialized Number onto tile, Initialize Tile Loop and If Grid is Even, Swap The Tiles Numbered 1 and 2

How to write a C Program to Calculate Grid Size, Initialized Number onto tile, Initialize Tile Loop and If Grid is Even, Swap The Tiles Numbered 1 and 2 in C Programming Language ?

Solution For C Program:
/*C Program to Calculate Grid Size, Initialized Number onto tile, Initialize Tile Loop and If Grid is Even, Swap The Tiles Numbered 1 and 2*/

C Program To Swap Two Numbers Without Using Third Variable

How to write a C Program To Swap Two Numbers Without Using Third Variable in C Programming Language ?


Solution For C Program :

/*C Program To Swap Two Numbers Without Using Third Variable.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the first no. a=");
scanf("%d",&a);
printf("Enter the second no. b=");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("After swaping numbers are:\na=%d\tb=%d",a,b);
getch();
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


C Program to Swap two variables without using third variable ?

How to write a C Program to Swap two variables without using third variable in C Programming Language ?


#include<stdio.h>
int main(){
    int a=5,b=10;
/* Type (a)*/
    a=b+a;
    b=a-b;
    a=a-b;
    printf("a= %d  b=  %d",a,b);

/* Type (a)*/
    a=5;
    b=10;
    a=a+b-(b=a);
    printf("\na= %d  b=  %d",a,b);
/* Type (a)*/
    a=5;
    b=10;
    a=a^b;
    b=a^b;
    a=b^a;
    printf("\na= %d  b=  %d",a,b);
   
/* Type (a)*/
    a=5;
    b=10;
    a=b-~a-1;
    b=a+~b+1;
    a=a+~b+1;
    printf("\na= %d  b=  %d",a,b);
   
/* Type (a)*/
    a=5,
    b=10;
    a=b+a,b=a-b,a=a-b;
    printf("\na= %d  b=  %d",a,b);
    return 0;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable


C Code/Program For Swap Matrix

How to write a C Program to Swap Matrix in C Programming Language ?


Solution:

#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main()
{
    int a[MAX][MAX],i,j,n,m,zbirG=0,zbirD=0,temp=0,d,g;
    scanf ("%d%d",&n,&m);
    for (i=0;i<n;i++){
      for (j=0;j<m;j++)
       scanf ("%d",&a[i][j]);
       }
 g=0; d=n-1;
 while (g<=d){
  for (j=0;j<m;j++){
   zbirG+=a[g][j];
   zbirD+=a[d][j]; }
   if (zbirG>zbirG){
    for (j=0;j<m;j++){
     temp=a[g][j];
     a[g][j]=a[d][j];
     a[d][j]=temp; }
   }
   g++; d--;
   zbirD=0; zbirG=0;
 }
           for (i=0;i<n;i++){
             printf ("\n");
      for (j=0;j<m;j++)
       printf ("%d ",a[i][j]);
           }
    return 0;
}