Miscellany
public text v1 · immutable#include <stdio.h>
#include <stdlib.h>
char *alternate(char c1, char c2, int n)
{
char *temp;
int i;
temp=(char *) malloc(n*sizeof(char)+1);
for (i=0;i<(n/2)*2;i+=2)
{
temp[i]=c1;
temp[i+1]=c2;
}
if (n%2!=0)
temp[n-1]=c1;
temp[n]='\0';
return temp;
}
main()
{
char a,b,*p;
int c;
scanf("%c",&a);
scanf("%c",&b);
scanf("%d",&c);
p=alternate(a,b,c);
puts(p);
system("pause");
}