0% found this document useful (0 votes)
9 views

Assignment 11

Uploaded by

vrunurade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Assignment 11

Uploaded by

vrunurade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Q1)

#include<stdio.h>

#include<string.h>

char*mystrchr(char*,char);

void main(){

char str[20];

prin ("Enter the string:");

gets(str);

char c;

prin ("\nEnter the Character you want to find:");

scanf("%c",&c);

if(mystrchr(str,c) == '\0'){

prin ("The character %c is not present in the String",c);

else{

prin ("The Character %c is found at the index %u",c,(mystrchr(str,c)-str));

char*mystrchr(char*str,char c){

int i = 0;

while(str[i] != '\0'){

if(str[i] == c)

return &str[i];

i++;

return '\0';

Q2)

#include<stdio.h>

#include<string.h>

void replacement(char*,char,char);
void main(){

char str[25];

prin ("Enter the String:");

gets(str);

replacement(str,'a','$');

prin ("The Final String is: %s",str);

void replacement(char*str,char c,char rep){

int i = 0;

while(str[i] != '\0'){

if(str[i] == c){

str[i] = rep;

i++;

Q3)

#include<stdio.h>

#include<string.h>

void nthRemoval(char*,int);

void main(){

char str[30];

prin ("Enter the String:");

gets(str);

int num;

prin ("Enter the Number:");

scanf("%d",&num);

nthRemoval(str,num);

prin ("Finally the String would be: %s",str);

void nthRemoval(char*str,int num){


while(str[num] != '\0'){

str[num] = str[num + 1];

num++;

Q4)

#include<stdio.h>

#include<string.h>

void exchange(char*);

void main(){

char str[30];

prin ("Enter the String:");

gets(str);

exchange(str);

prin ("The Final String would be: %s",str);

void exchange(char*str){

int x = strlen(str) - 1;

char temp = str[0];

str[0] = str[x];

str[x] = temp;

Q5)

#include<stdio.h>

#include<string.h>

void main(){

char str[25];

prin ("Enter the String:");

gets(str);

prin ("There are %d vowels in the given String",vowelcount(str));

}
int vowelcount(char*str){

int i = 0,count = 0;

char vowels[11] = "aeiouAEIOU";

while(str[i] != '\0'){

if(strchr(vowels,str[i]) != '\0')

count++;

i++;

return count;

Q6)

#include<stdio.h>

#include<string.h>

void replacement(char*,char,char);

void main(){

char str[25];

prin ("Enter the String:");

gets(str);

replacement(str,' ','@');

prin ("The Final String is: %s",str);

void replacement(char*str,char c,char rep){

int i = 0;

while(str[i] != '\0'){

if(str[i] == c){

str[i] = rep;

i++;

}
Q7)

#include<stdio.h>

#include<string.h>

void main(){

char str[30];

prin ("Enter the String:");

gets(str);

removeOdd(str);

prin ("%s",str);

removeOdd(char*str){

int i = 1;

while(str[i] != '\0'){

if(i%2 == 0){

str[i/2] = str[i];

i++;

if(i%2 == 0){

str[i/2] = '\0';

else

str[i/2 + 1] = '\0';

Q8)

#include<stdio.h>

#include<string.h>

void main(){

char str[30];

prin ("Enter the String:");

gets(str);
prin ("There are %d words in the given String",words(str));

int words(char*str){

int i = 1,count = 1;

while(str[i] != '\0'){

if(str[i] == ' ' && str[i+1] != '\0' && str[i-1] != ' ')

count++;

i++;

return count;

Q9)

#include<stdio.h>

#include<string.h>

void main(){

char str1[20];

prin ("Enter First String:");

gets(str1);

char str2[20];

prin ("\nEnter Second String:");

gets(str2);

if(mystrcmp(str1,str2) > 0)

prin ("First String is Greater");

else if(mystrcmp(str1,str2) < 0)

prin ("Second String is Greater");

else

prin ("Both the Strings are equal");

int mystrcmp(char*str1,char*str2){

int i = 0;
while(str1[i] != '\0' || str2[i] != '\0'){

if(str1[i] > str2[i])

return 1;

else if(str1[i] < str2[i])

return -1;

i++;

return 0;

Q10)

#include<stdio.h>

#include<string.h>

int palindrome(char*);

void main(){

char str[25];

prin ("Enter a String:");

gets(str);

if(palindrome(str) == 1){

prin ("The given string is an Palindrome.");

else

prin ("The given String is Not an Palindrome.");

int palindrome(char*str){

char temp[25];

strcpy(temp,str);

strrev(str);

if(strcmp(temp,str) == 0)

return 1;

else

return 0;
}

You might also like