String concatenation in c without using strcat Function


#include
#include

void stringConcat(char[],char[]);
int main()
{
char strl[100],str2[100];
int compare;
clrscr();
printf(“\nEnter first string: \n”);
scanf(“%s”,strl);
printf(“\nEnter second string: “);
scanf(“%s”,str2);
stringConcat(strl,str2);
printf(“\nString after concatenation: %s”,strl);
return 0;
getch();
}

void stringConcat(char strl[],char str2[])
{
int i=0,j=0;
while(strl[i]!=”)
{
i++;
}
while(str2[j] ! = ”)
{
strl[i] = str2[j] ;
i++;
j++;
}

strl[i] = ‘ ‘;
}

C Program to Count chars,spaces,tabs and newlines in a file





#include<stdio.h>
#include<conio.h>
void main()
{
   FILE *fp;
   char ch;
   int nol=0,not=0,nos=0,noc=0;
   clrscr();
   fp=fopen(“animesh.txt”,”r”);
   while(1)
   {
      ch=fgetc(fp);
      if(ch==EOF)
      break;
      noc++;
      if(ch==’ ‘)
      nos++;
      if(ch==’\n’)
      nol++;
      if(ch==’\t’)
      not++;
   }
   fclose(fp);
   printf(“\n Number of characters = %d”,noc);
   printf(“\n Number of blanks = %d”,nos);
   printf(“\n Number of tabs = %d”,not);
   printf(“\n Number of lines = %d”,nol);
   getch();
}


C PROGRAM TO PRINT ALL PERFECT NUMBERS BETWEEN 1 AND N AND THEN FIND THE SUM AND AVERAGE


#include <stdio.h>

#include<conio.h>
main()
{
    int n,sum = 0,s=0,c=0;
    float avg=0.0;
    printf(“\n Enter Limit :-\n”);
    scanf(“%d”,&n);
    printf(“\nTo print all the perfect no. between 1 and %d”,n);
    for(int num=1;num <=n;num++)
    {
            sum = 0;
            for(int i = 1; i < num; i++)
            {
            if(!(num%i))
            {
            sum+=i;
            }
            }
            if(sum == num)
            {
            s=s+sum;c++;       
            printf(“\n\n%d is a perfect number”,num);
            }
  }
  avg=(float)s/c;
  printf(“\n\nthe sum and average of the perfect numbers are=%d and %f”,s,avg);
  getch();
}

Program in C for Decimal to Roman Number conversion


/* Program in C for Decimal to Roman Number conversion */

#include<stdio.h>
#include<conio.h>

main()
{
int a,b,c,d,e;

printf(“Input a number (between 1-3000):”);
scanf(“%d”,&e);
while (e==0||e>3000)
{
printf (“ERROR: Invalid Input!”);
printf (“Enter the number again:”);
scanf (“%d”,&e);
}
if (e>3000)
printf(“Invalid”);
a = (e/1000)*1000;
b = ((e/100)%10)*100;
c = ((e/10)%10)*10;
d = ((e/1)%10)*1;

if (a ==1000)
printf(“M”);
else if (a ==2000)
printf(“MM”);
else if (a ==3000)
printf(“MMM”);

if (b == 100)
printf(“C”);
else if (b == 200)
printf(“CC”);
else if (b == 300)
printf(“CCC”);
else if (b == 400)
printf(“CD”);
else if (b ==500)
printf(“D”);
else if (b == 600)
printf(“DC”);
else if (b == 700)
printf(“DCC”);
else if (b ==800)
printf(“DCCC”);
else if (b == 900)
printf(“CM”);


if (c == 10)
printf(“X”);
else if (c == 20)
printf(“XX”);
else if (c == 30)
printf(“XXX”);
else if (c == 40)
printf(“XL”);
else if (c ==50)
printf(“L”);
else if (c == 60)
printf(“LX”);
else if (c == 70)
printf(“LXX”);
else if (c ==80)
printf(“LXXX”);
else if (c == 90)
printf(“XC”);

if (d == 1)
printf(“I”);
else if (d == 2)
printf(“II”);
else if (d == 3)
printf(“III”);
else if (d == 4)
printf(“IV”);
else if (d ==5)
printf(“V”);
else if (d == 6)
printf(“VI”);
else if (d == 7)
printf(“VII”);
else if (d ==8)
printf(“VIII”);
else if (d == 9)
printf(“IX”);
getch();
}

C Program to print a linked list in reverse


#include<stdio.h>
#include<conio.h>

typedef struct linked_list
{
int item;
struct linked_list *next;
}node;

node *create_list();
void print_list(node *);
void print_list_in_reverse(node *);

int main()
{
node *head=NULL;

printf("you can create a list by entering elements press -999 to end\n");
head=create_list();
printf("\n The list is\n");
print_list(head);
printf("\n The list in reverse order is");
print_list_in_reverse(head);
printf("\n");
return 0;
}

node *create_list()
{
int x;
node *temp=NULL;
scanf("%d",&x);
if(x!=-999)
{
temp=(node*)malloc(sizeof(node));
temp->item=x;
temp->next=NULL;
temp->next=create_list();
}
return temp;
}
void print_list(node *p)
{
if(p)
{
printf("%d ",p->item);
print_list(p->next);
}
else
printf("\n");
}

void print_list_in_reverse(node *p)
{
if(p)
{
print_list_in_reverse(p->next);
printf("%d ",p->item);
}
else
printf("\n");
}

C Program to draw SWASTIKA on center on the screen with blink effect


 #include<stdio.h> 

#include<conio.h> 

void main()

{

int i=0;

clrscr();

textcolor(RED+BLINK);

for(i=8;i<25;i++)

{

gotoxy(20,i); cprintf(“*”);

gotoxy(40,i); cprintf(“*”);

if(i<23)

gotoxy(20+2,i);

cprintf(“*”);

gotoxy(40+2,i+2); 

cprintf(“*”);

}

}


for(i=23;i<=40;i++)

{

if(i<39)

{

gotoxy(40,i);

cprintf(“*”);

gotoxy(60,i+2); 

cprintf(“*”);


}


gotoxy(40+2,i); 

cprintf(“*”);

gotoxy(60+2,i); c

printf(“*”);

}

for(i=20;i<42;i++)

{

gotoxy(i,25);

cprintf(“*”);

gotoxy(i,40); 

cprintf(“*”);

if(i<40)

{

gotoxy(i+2,25-2);

cprintf(“*”);

gotoxy(i,40-2); cprintf(“*”);

}

}

for(i=40;i<62;i++) 

{

if(i<60)

{

gotoxy(i+2,10);

cprintf(“*”);

gotoxy(i,25);

cprintf(“*”);

}

gotoxy(i,10-2); 

cprintf(“*”);

gotoxy(i,25-2); 

cprintfr*”);

getch();

}


OUTPUT IN C