Welcome To Uday Satya Blog

52 - 56 PROGRAMS



/* ***************************************
          52.To find the length of a string
   *************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{
 clrscr();
 char s[100];
 int l;
 printf("Enter the string ");
 scanf("%s",&s);

 l=strlen(s);

printf("\nThe string length is %d",l);

getch();
}

OUTPUT
Enter the string Memory

The string length is 6

/* ************************************************
          53.To concatenate 2 strings
   *********************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{clrscr();
 char s[100],t[100];
 int l,c;
 printf("Enter the first string ");
 scanf("%s",&s);
 printf("Enter the second string ");
 scanf("%s",&t);

 strcat(s,t);

 printf("\nThe concatenated string is : %s",s);

getch();
}

OUTPUT
Enter the first string Computer
Enter the second string Applications

The concatenated string is : ComputerApplications


/* *********************************************************
        54.To check if a string is a palindrome or not
   ******************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{
clrscr();
 char s[100],t[100];
 int l,c;
 printf("Enter the string ");
 scanf("%s",&s);

 strcpy(t,s);
 strrev(s);
 c=strcmp(t,s);

if(c==0)
printf("\nThe string is a palindrome");

getch();
}

OUTPUT
Enter the string ABBA

The string is a palindrome

/* ********************************************************************
                55.To copy one string to another
  ******************************************************************** */
#include<*stdio.h>
#include<*conio.h>
#include
void main()
{clrscr();
 char s[100],t[100];
 int l,c;
 printf("Enter the string ");
 scanf("%s",&s);

 strcpy(t,s);

 printf("\nThe entered string is : %s",s);
 printf("\nThe copied string is : %s",t);

getch();
}

OUTPUT
Enter the string Hyderabad

The entered string is : Hyderabad
The copied string is : Hyderabad

/* **********************************************************************
   56.To find the sum of the first n natural numbers using functions
  ************************************************************************ */
#include
#include
int sum(int);

void main()
{
int n,s;
 clrscr();
 printf("Enter the limit\n");
 scanf("%d",&n);
 s=sum(n);
 printf("The sum of the first %d natural numbers is %d",n,s);
 getch();
 }
int sum(int n)
{
int s=0;
 for(int i=1;i<=n;i++)
  s=s+i;
 return(s);
 }

OUTPUT
Enter the limit
6
The sum of the first 6 natural numbers is 21

0 comments:

Post a Comment