Practical 5
Practical 5
kc !!coll
Input:-
#include<stdio.h>
#include<string.h>
void main()
Output:-
The length of KC COLLEGE string is 10
#include<string.h>
void main()
char str2[30];
strcpy(str2,str1);
Output:-
Value of string s2 is KC COLLEGE
4. Write a c program to declare and initialize 2 string variables with string values
and join both strings
Input:-
#include<stdio.h>
#include<string.h>
void main()
}
Output:-
Value of string s2 is GOOD MORNINGKC COLLEGE
5. Write a c program to declare and initialize 2 string variables with string values
and compare both strings
Input:-
#include<stdio.h>
#include<string.h>
void main()
int result;
result=strcmp(str1,str2);
Output:-
The result is -1
6. Write a c program to read and display a character using getchar() and putchar()
functions
Input:-
#include <stdio.h>
#include <string.h>
void main()
int c;
c=getchar();
putchar(c);
Output:-
Enter the value: 54
7. Write a c program to read and display a string using gets() and puts()functions
Input:-
#include<stdio.h>
#include<string.h>
void main()
{
char str[50];
printf("Enter the value:");
gets(str);
printf("Entered value is:");
puts(str);
}
Output:-
Enter the value:14
Input:-
#include <stdio.h>
#include <string.h>
void main()
char flag;
flag=getche();
if(flag=='Y')
else
Output:-
}
Output:-
String before strrev():Hello
String after strrev():olleH
Input:-
#include<stdio.h>
#include<string.h>
void main()
char string[100];
gets(string);
Output:-
Input a string to convert to lower case
HELLO WORLD
#include<string.h>
void main()
char string[100];
gets(string);
Output:-
Input a string to convert to upper case
hello world
#include<string.h>
void main()
char str[100],ch;
int i, frequency=0;
printf("Enter a string:\n");
gets(str);
scanf("%c",&ch);
for (i=0;str[i]!='\0';++i)
if(ch==str[i])
++frequency;
printf("Frequency of%c=%d",ch,frequency);
Output:-
Enter a string:
Frequency ofs=4
13. Write a c program to display the ASCII value of character entered by the user
Input:-
#include<stdio.h>
#include<string.h>
void main()
char ch;
scanf("%c",&ch);
Output:-
Enter the character:
Inputs:-
#include<stdio.h>
#include<string.h>
void main()
char line[150];
scanf("%[^\n]",line);
for(i=0;line [i]!='\0';++i)
++vowels;
++consonants;
++digits;
++spaces;
}
printf("Vowels:%d",vowels);
printf("\nConsonants:%d",consonants);
printf("\nDigits:%d",digits);
printf("\nWhite spaces:%d",spaces);
Output:-
there was a person whose name was Gajodhar he was 45 year old
Vowels:19
Consonants:28
Digits:2
White spaces:13