- Write a program take an address form user and check it is Kathmandu or not in C language.#include<stdio.h>#include<string.h>int main(){char address[20];printf("Enter an address: ");scanf("%s", address);if(strcmp(address, "kathmandu") == 0){printf("You have enter Kathmandu");}else{printf("You havenot enter Kathmandu");}return 0;}
- Write a program, take 3 string data from user and find smallest in C language.#include<stdio.h>#include<string.h>int main(){char a [20], b[20], c[20];printf("Enter first string data: ");scanf("%s", a);printf("Enter second string data: ");scanf("%s", b);printf("Enter third string data: ");scanf("%s", c);if(strcmp(a,b) >= 0 && strcmp(c,b) >= 0){printf("The smallest string is %s", b);}else if(strcmp(a,b) <= 0 && strcmp(a,c) <= 0){printf("The smallest string is %s", a);} else{printf("The smallest string is %s", c);}return 0;
- Enter Two Strings and use strcat
#include <stdio.h>
#include<string.h>
int main(){
char str1[10];
char str2[10];
printf("Enter Two strings:\n");
gets(str1);
gets(str2);
printf("\nTwo string concantinated as %s",strcat(str1,str2));
return 0;} - Enter Two Strings and use strlen
#include <stdio.h>
#include<string.h>
int main(){
char str1[10];
char str2[10];
printf("Enter Two strings:\n");
gets(str1);
gets(str2);
printf("Length of Fist is %d \n",strlen(str1));
printf("Length of 2nd is %d \n",strlen(str2));
return 0;}
0 Comments had been done yet:
Post a Comment