Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Q1. Q3.

#include <stdio.h> #include <stdio.h>


#include <ctype.h> #include <stdlib.h>
#include <string.h>
void main(){ void main(){
int i, length; int a, b, c, d;
char s1[50]; char s1[50], s2[50], s3[50], s4[50];
printf("Enter line of text :: "); printf("Enter 1st string that represents integers
gets(s1); :: ");
length=strlen(s1); gets(s1);
printf("\nText in lower case :: "); a = atoi(s1);
for(i=0;i<length;i++) printf("Enter 2nd string that represents
printf("%c",tolower(s1[i])); integers :: ");
printf("\nText in upper case :: "); gets(s2);
for(i=0;i<length;i++) b = atoi(s2);
printf("%c",toupper(s1[i])); printf("Enter 3rd string that represents
} integers :: ");
gets(s3);
Q2. c = atoi(s3);
#include <stdio.h> printf("Enter 4th string that represents
#include <ctype.h> integers :: ");
#include <string.h> gets(s4);
d = atoi(s4);
void main(){ printf("Result of adding four numbers = %d",
int i, length, letters=0, digits=0, special=0; a+b+c+d);
char s1[50]; }
printf("Enter line of text :: "); Q4.
gets(s1); #include <stdio.h>
length=strlen(s1); #include <string.h>
for(i=0;i<length;i++)
if(isdigit(s1[i])) void main(){
digits++; char s1[50], s2[50];
else if(isalpha(s1[i])) printf("Enter 1st string :: ");
letters++; gets(s1);
else printf("Enter 2nd string to compare :: ");
special++; gets(s2);
printf("\nNo. of letters = %d",letters); if(strcmp(s1,s2) < 0)
printf("\nNo. of digits = %d",digits); printf("%s is less than %s", s1, s2);
printf("\nNo. of special symbols = %d",special); else if(strcmp(s1,s2) > 0)
} printf("%s is greater than %s", s1, s2);
else
printf("%s is equal to %s", s1, s2);
}
Q5. Q7.
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>

void main(){ void main(){


int i, length; int i, length, sw=0;
char s1[50], s2[50]; char s1[50], ch;
printf("Enter the line of text to print in printf("Enter the string :: ");
reverse order :: "); gets(s1);
gets(s1); printf("Enter the character to search :: ");
length=strlen(s1); ch = getchar();
for(i=0; i<length; i++) length=strlen(s1);
s2[length-i-1] = s1[i]; for(i=0; i<length; i++)
s2[i]='\0'; if(s1[i]==ch)
printf("%s is the reversed string of %s",s2,s1); sw=1;
} if(sw==1)
printf("%c is found in %s", ch, s1);
Q6. else
#include <stdio.h> printf("%c is not found in %s", ch, s1);
#include <string.h> }
void main(){ Q8.
int i, length; #include <stdio.h>
char s1[50], s2[50]; #include <string.h>
printf("Enter the string to check palindrome or
not :: "); void main(){
gets(s1); int i, length, sw=0, found;
length=strlen(s1); char s1[50], ch;
for(i=0; i<length; i++) printf("Enter the string :: ");
s2[length-i-1] = s1[i]; gets(s1);
s2[i]='\0'; printf("Enter the character to search :: ");
if(strcmp(s1,s2)==0) ch = getchar();
printf("%s is a palindrome",s1); length=strlen(s1);
else for(i=0; i<length; i++)
printf("%s is not a palindrome",s1); if(s1[i]==ch){
} sw=1;
found=i+1;
}
if(sw==1)
printf("%c is found at %d", ch, found);
else
printf("%c is not found", ch);
}

You might also like