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

It18111 - Programming For Problem Solving Laboratory EX - NO: 6.a Date

The document provides a programming problem to determine if a given string is a palindrome. It defines a palindrome as a sequence of characters that reads the same backward or forward. It asks the student to write a program that takes input of multiple strings, reverses each string, compares it to the original, and outputs whether it is a palindrome or not. If it is a palindrome, it also outputs whether it has even or odd length. Sample input and output is provided.

Uploaded by

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

It18111 - Programming For Problem Solving Laboratory EX - NO: 6.a Date

The document provides a programming problem to determine if a given string is a palindrome. It defines a palindrome as a sequence of characters that reads the same backward or forward. It asks the student to write a program that takes input of multiple strings, reverses each string, compares it to the original, and outputs whether it is a palindrome or not. If it is a palindrome, it also outputs whether it has even or odd length. Sample input and output is provided.

Uploaded by

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

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 6.a
DATE:
Solving problems using Strings

QUESTION:
Reshmi is given the task of printing the frequency of the digits that occur in the given string starting
from 0 to 9. Help her out to solve the same using C language.
Eg: b1n33m6769
O/p: 0 1 0 2 0 0 2 1 0 1

AIM:

ALGORITHM:

PROGRAM:

Roll Number: Page No.:


#include<stdio.h>
#include<stdlib.h>
void main()
{
char a[15];
int b[10]={0},i;
printf("Enter the string ");
gets(a);
for(i=0;a[i]!='\0';i++)
if('0'<=a[i]&&a[i]<='9')
b[a[i]-48]++;
for(i=0;i<10;i++)
printf("%d ",b[i]);
}

SAMPLE INPUT AND OUTPUT:

Testcase:1
Enter the string f946v4h81202
1120201011

Testcase:2
Enter the string k984084nt2xgd7
1010200121

RESULT:

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

Roll Number: Page No.:


EX.NO: 6.b
DATE:
Solving problems using Strings

QUESTION:
Kavi was working in a project at Hakuna Mattata Technologies Ltd. She was given a task of
creating password for the users. The conditions to create the password are as follows:
It should be 8 characters long. First two characters are the first and last characters of the
First name. Next 4 characters are the year of birth of the user. Last two characters are the last and
first characters of the Last name. Note: The password should retain the case of the input.
Eg:
Enter First Name: Rajiv
Enter Last Name: Shukla
Enter Year of Birth: 1985
O/p: Rv1985aS

AIM:

ALGORITHM:

Roll Number: Page No.:


PROGRAM:
#include<stdio.h>
#include<string.h>
void main()
{
char x[6],a[15],b[15],y[4];
int i,l;
printf("Enter the first name");
gets(a);
printf("Enter the last name");
gets(b);
printf("Enter your year of birth");
gets(y);
l=strlen(a);
x[0]=a[0];
x[1]=a[l-1];
strcat(x,y);
l=strlen(b);
x[6]=b[l-1];
x[7]=b[0];
printf("Result:%s",x);
}

SAMPLE INPUT AND OUTPUT:


Enter the first name: Naveen
Enter the last name: Sriram
Enter year of birth: 2000
Result:Nn2000mS

RESULT:

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 6.c
DATE:

Roll Number: Page No.:


Solving problems using Strings

QUESTION:
Write a program to print the string in the following pattern
h
he
hel
hell
hello
hello
hell
hel
he
h

AIM:

ALGORITHM:

Roll Number: Page No.:


PROGRAM:
#include<stdio.h>
void main()
{
char x[]="Hello";
int i,j;
for(i=0;x[i]!='\0';i++)
{
for(j=0;j<=i;j++)
printf("%c",x[j]);
printf("\n");
}
for(i--;i>=0;i--)
{
for(j=0;j<=i;j++)
printf("%c",x[j]);
printf("\n");
}
}

SAMPLE INPUT AND OUTPUT:


H
He
Hel
Hell
Hello
Hello
Hell
Hel
He
H

RESULT:

IT18111 – PROGRAMMING FOR PROBLEM SOLVING LABORATORY

EX.NO: 6.d
DATE:
Solving problems using Strings

QUESTION:

Roll Number: Page No.:


Heisenberg introduces the concept of palindrome saying, "A palindrome is a sequence of
characters which reads the same backward or forward." Now, since he loves things to be binary,
he asks you to find whether the given string is a palindrome or not. If a given string is a palindrome,
you need to state that it is even palindrome (palindrome with even length) or odd palindrome
(palindrome with odd length).

Input:
The first line consists of T, denoting the number of test cases. Next follow T lines, each line
consisting of a string of lowercase English alphabets.
Output:
For each string , you need to find out whether it is a palindrome or not. If it is not a palindrome,
print NO.
If it is a palindrome, print YES followed by a space; then print EVEN it is an even palindrome else
print ODD.
Output for each string should be in a separate line. See the sample output for clarification.
I/p:
3
abc
abba
aba
O/p:
NO
YES EVEN
YES ODD

AIM:

ALGORITHM:

Roll Number: Page No.:


PROGRAM:
#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char a[10][20],b[20];
int i,n;
clrscr();
printf("Enter number of strings ");
scanf("%d",&n);
printf("Enter the strings ");
for(i=0;i<n;i++)
scanf("%s",a[i]);
for(i=0;i<n;i++)
{
strcpy(b,a[i]);
strrev(a[i]);
if(strcmp(a[i],b)==0)
if(strlen(a[i])%2==0)
printf("YES EVEN\n");
else
printf("YES ODD\n");
else
printf("NO\n");
}

Roll Number: Page No.:


}

SAMPLE INPUT AND OUTPUT:

Enter the number of strings 3


Enter the strings hello
madam
abba
NO
YES ODD
YES EVEN

RESULT:

Roll Number: Page No.:

You might also like