0% found this document useful (0 votes)
5 views1 page

CP 2 Back

The document contains C programming examples, including a program to reverse a string and check if a string is a palindrome without using built-in functions. It also includes code for counting vowels, consonants, and white spaces in a string, as well as checking if a number is an Armstrong number. The document provides sample outputs for the programs and references for further study materials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

CP 2 Back

The document contains C programming examples, including a program to reverse a string and check if a string is a palindrome without using built-in functions. It also includes code for counting vowels, consonants, and white spaces in a string, as well as checking if a number is an Armstrong number. The document provides sample outputs for the programs and references for further study materials.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

EST102 Programming in C

rev[j]=str[i];
j++;
https://www.keralanotes.com/
i--;
}
rev[j]='\0';
printf("\nReverse=%s",rev);
}
Output
Enter the string: hello
Reverse=olleh

3. Write a program to check whether a string is palindrome or not without using in


built functions. PROGRAM
#include<stdio.h>
#include<string.h> #include <stdio.h>
void main() void main()
m

{ {
char a [25];
co

char str[20];
int len,i,j,flag; int v=0,c=0,S=0;
printf ("Enter the string :");
printf("Enter the string:");
s.

gets (a);
gets(str);
te

// Code to find string length


for (int i=0; a[i]!= '\0'; i++)
for(len=0;str[len]!='\0';len++);
{
no

// Code to check the Palindrome


if(a[i] == 'a'||a[i]=='e'|| a[i]=='i' || a[i]=='o'|| a[i]=='u'|| a[i]=='A'|| a[i]=='E' || a[i] == 'I' || a[i]=='O' ||
flag=0;
a[i]== 'U')
for(i=0;i<len/2;i++)
la

{
{ v=v+1;
ra

if(str[i] != str[len-i-1]) }
{
ke

flag=1; else if (a[i]==' ')


break; {
} S=S+1;
https://www.keralanotes.com/

} }
27

if(flag == 0)
EST102 Programming in C

for loop is similar to while, for statements are often used to process lists such a

{ else
printf("\nPalindrome"); {
} c = c+1;
For More Study Materials : www.keralanotes.com

else }
m

{ }
printf("\nNot Palindrome"); printf("Number of vowels %d\n",v);
co

} printf("Number of white space %d\n",S);


printf("Number of consonants %d\n",c);
s.

}
}
// To count the number of digits in the number

t e

IIPE
no

17
rev = sum + pow(temp,count);

for( expression1; expression2; expression3)


printf("\nNot Armstrong");
a

For More Study Materials : www.keralanotes.com


printf("\nArmstrong");
int n,sum=0,temp,org,count=0;

Basic syntax of for loop is as follows:


al

OUTPUT
printf("Enter the number:");

Enter the string :aeiou abc ghf


r
ke
temp = n%10;

Number of vowels 6
n = n/10;

Number of white space 2


scanf("%d",&n);

count++;
n=n/10;

Enter the number:153


if( org == sum)
while ( n > 0 )
while( n > 0)

Number of consonants 5
Armstrong or not.

#include <math.h>
#include <stdio.h>

range of numbers.
org=n;
void main()

else

Armstrong
OUTPUT

for loop
{

IIPE
{

You might also like