C program that contains a string XOR each character in this string with 0 ,127

Write a C program that contains a string (char pointer) with a
value \Hello World’. The program should XOR each character
in this string with 0 and displays the result.

Program:

#include<stdlib.h>
main()
{
char str[]="Hello World";
char str1[11];
int i,len;
len=strlen(str);
for(i=0;i<len;i++)
{
str1[i]=str[i]^0;
printf("%c",str1[i]);
}
printf("\n");
}



Q.2 Write a C program that contains a string (char pointer) with a value \Hello
World’. The program should AND or and XOR each character in this string with
127 and display the result.


PROGRAM:

#include <stdio.h>
#include<stdlib.h>
void main()
{
char str[]="Hello World";
char str1[11];
char str2[11]=str[];
int i,len;
len = strlen(str);
for(i=0;i<len;i++)
{
str1[i] = str[i]&127;
printf("%c",str1[i]);
}
printf("\n");
for(i=0;i<len;i++)
{
str3[i] = str2[i]^127;
printf("%c",str3[i]);
}
printf("\n");
}

Comments

Popular posts from this blog

Queue in Data Structure(DS)

Implementation of stack Using Array