-->
Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Wednesday, June 4, 2025

c program to concatenate two strings | 2D strings examples in c | program without strcat()

Array and string programs in C

 // program to concatenate two strings without using strcat()

#include<stdio.h>

int main()

{

char string1[100],string2[100];

int i=0,j=0;

printf("enter first string");

gets(string1);

printf("enter second string");

gets(string2);

while(string1[i]!='\0')

{

i++;

}

while(string2[j]!='\0')

{

string1[i]=string2[j];

i++;

j++;

}

string1[i]='\0';

printf("the concatenated string=%s",string1);

return 0;

}


output:-

c program to concatenate two strings without strcat()







c program to count total characters present in a strings | 2D strings examples in c

Array program collection C 


/* program to store multiple strings and count  total their characters

*/

#include<stdio.h>

int main()

{

char string[5][100]={"c program","C++ code","JS code","php code","java code"};

int i,j,count;

for(i=0;i<=4;i++)

{

count=0;

for(j=0;string[i][j]!='\0';j++)

{

count++;

}

printf("the string is %s and its length is %d\n",string[i],count);

}

return 0;

}

Output:

c program to count total letters present in strings



Wednesday, October 7, 2015

program to input number of passenger and destination through air.This program should print name,destination,number of passenger and total fare

//a program to input number of passenger and destination through air.This program should print //name,destination,number of passenger and total fare using following rate.
//Destination                                                                  Rate
//      Pokhara                                                                 Rs. 2400
//    Bharaiwa                                                                 Rs. 2500
//     Biratnagar                                                               Rs. 800
//     Bhadrapur                                                               Rs. 2550
#include<stdio.h>
#include<conio.h>
void main()
{

int no_passenger;
char name[200],destination[200];
float total_fare;
printf("enter total passenger\n");
scanf("%d",&no_passenger);
printf("enter passenger name\n");
gets(name);
printf("enter destination\n");
gets(destination);
if((strcmp(destination,Pokhara))==0)
{
total_fare= 2400*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);
}
elseif(((strcmp(destination,Bhairawa))==0)
{
total_fare= 2500*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);

}
elseif(((strcmp(destination,Biratnagar))==0)
{
total_fare= 800*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);

}
elseif(((strcmp(destination,Bhadrapur))==0)
{
total_fare= 2550*no_passenger;
  printf("%s ,total passenger=%d and destination=%s\n",name,no_passenger,destination);

}
getch();
}