Computer Science, asked by kushal7935, 1 year ago

C' program to swap the alternate digits of the given number

Answers

Answered by Aishwarya98
21
#include<stdio.h>
#include<conio.h>
void main()
{
int array[10],i;
printf("Enter the elements:");
for(i=0;i<10;i+=2)
scanf("%d",&array[i]);
printf("Alternate elements of a given array:");
for(i=0;i<10;i+=2)
printf("%d\n",array[i]);
}
Answered by topanswers
4

#include <stdio.h>

#include <conio.h>

#include <string.h>

void main(){

    char str[20],tmp;

    int i,j;

    clrscr();

    printf("\nEnter a string : ");

    scanf("%s",str);

    printf("\n\nOriginal String     : %s",str);

    for(i=0;i<strlen(str);i=i+2){

    tmp = str[i];

    str[i] = str[i+1];

    str[i+1] = tmp;

    }

    printf("\nAfter Swap String      : %s",str);

    getch();

}

Similar questions