Pages

Tuesday, December 6, 2016

C program to merge (concatenate) String and Integer variable.

This special program shows that how to merge string and integer type of variable in C language.

#include<stdio.h>
int main()
{
char str[10], newstr[15]; 
int number; 

printf("Enter your string:");
gets(str);

printf("Enter your number:");
scanf("%d",&number);

sprintf(newstr,"%s%d",str,number); 
printf("%s",newstr);
}

Output of the program:

Enter your string:MCA
Enter your number:101
MCA101

* * * * *

No comments:

Post a Comment