0% found this document useful (0 votes)
21 views

Experiment No-8: 1104014155/megha Vig

The document describes 12 experiments involving C programs to perform various string and number operations. Experiment 8 writes a program to read a string and output it in reverse order. Experiment 9 concatenates two strings by copying the first string into a third string, then copying the second string after it. Experiment 10 checks if a string is a palindrome by comparing the first and last characters, then moving inward.

Uploaded by

Andres Stevens
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Experiment No-8: 1104014155/megha Vig

The document describes 12 experiments involving C programs to perform various string and number operations. Experiment 8 writes a program to read a string and output it in reverse order. Experiment 9 concatenates two strings by copying the first string into a third string, then copying the second string after it. Experiment 10 checks if a string is a palindrome by comparing the first and last characters, then moving inward.

Uploaded by

Andres Stevens
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

EXPERIMENT NO-8

AIM: WRITE A PROGRAM TO READ A STRING AND WRITE IT IN A REVERSE


ORDER.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char arr[10];
int i,j=0,k=0;
clrscr();
printf("Enter the string :");
scanf("%s",&arr);
for(i=0;arr[i]!='\0';i++)
{ k++;
}
printf("No.of Character in the string is %d",k);
printf("\nReverse String is");
for(j=k;j>=0;j--)
{
printf("%c",arr[j]);
}
getch();

1104014155/Megha vig

15

15

}
OUTPUT:-

1104014155/Megha vig

15

EXPERIMENT NO-9
AIM: WRITE A PROGRAM TO CONCATENATE TWO STRINGS.
Source Code:
#include<stdio.h>
#include<conio.h>
void main()
{
char a[25],b[25],c[25];
int i,j;
clrscr();
printf("Enter first string:\t");
scanf("%s",a);
printf("Enter second string:\t");
scanf("%s",b);
for(i=0;a[i]!='\0';i++)
c[i]=a[i];
for(j=0; b[j]!='\0'; j++)
c[i+j]=b[j];
c[i+j]='\0';
printf("The concatenated string is:\n%s",c);
getch();
}

1104014155/Megha vig

15

OUTPUT:-

1104014155/Megha vig

15

EXPERIMENT NO-10
AIM: WRITE A PROGRAM CHECK WHETHER INPUT STRING IS PALIDROME OR
NOT.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
int i,k=0,j;
int flag=1;
clrscr();
printf( Enter a string: );
gets(str);
for(i=0;str[i]!='\0';i++)
{
k++;
}
printf(" Length of a string is %d\n", k);
for (i=k;i>=0;i--)
{printf("%c",str[i]); }
for(i=0,j=(k-1);i<=k/2;i++,j--)
{

1104014155/Megha vig

15

if(str[j]!=str[i])
{
flag=0;
break;
}}
if (flag==1)
{
printf(" is a Palindrome");
}
else
{
printf(" is not a Palindrome");
}
getch();
}

1104014155/Megha vig

15

OUTPUT:-

1104014155/Megha vig

15

EXPERIMENT NO-11
AIM: WRITE A PROGRAM TO CHECK GIVEN NUMBER IS PRIME NUMBER OR
NOT.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int n, i, flag=0;
clrscr();
printf(" Enter a positive integer: ");
scanf(" %d",&n);
for(i=2;i<=n/2;i++)
{
if(n%i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf(" %d is a prime number.",n);
else
printf(" %d is not a prime number.",n);

1104014155/Megha vig

15

getch();
return 0;
}

1104014155/Megha vig

15

OUTPUT:-

1104014155/Megha vig

15

EXPERIMENT NO-12
AIM: WRITE A PROGRAM TO CHECK GIVEN NUMBER IS EVEN OR ODD.
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int num;
clrscr();
printf(" Enter an integer you want to check: ");
scanf(" %d",&num);
if((num%2)==0)

/* Checking whether remainder is 0 or not. */

printf(" %d is even.",num);
else
printf(" %d is odd.",num);
getch();
return 0;
}

1104014155/Megha vig

15

OUTPUT:-

1104014155/Megha vig

15

You might also like