0% found this document useful (0 votes)
13 views4 pages

Practise Quesion

The document contains multiple C programs that demonstrate various functionalities such as checking if a string is a palindrome, performing memory allocation using malloc, checking if a number is a palindrome, and calculating the length of a string. Each program includes user input, processing logic, and output statements. The code snippets illustrate basic programming concepts and operations in C.

Uploaded by

Bk Lokendra
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)
13 views4 pages

Practise Quesion

The document contains multiple C programs that demonstrate various functionalities such as checking if a string is a palindrome, performing memory allocation using malloc, checking if a number is a palindrome, and calculating the length of a string. Each program includes user input, processing logic, and output statements. The code snippets illustrate basic programming concepts and operations in C.

Uploaded by

Bk Lokendra
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/ 4

// to check string is palindrome or not

#include<conio.h>

#include<stdio.h>

void main()

char one[10],two[10];

int cmp;

printf("enter a string ");

scanf("%s",one);

strcpy(two,one);

strrev(one);

cmp=strcmp(one,two);

if(cmp==0)

printf(" given string is palindrome ");

else

printf(" string is not a palindrome");

getch();

}
// to perform malloc operation

#include<stdio.h>

#include<stdlib.h>

int main(){

int n,i,*ptr,sum=0;

printf("Enter number of elements: ");

scanf("%d",&n);

ptr=(int*)malloc(n*sizeof(int)); //memory allocated using malloc

if(ptr==NULL)

printf("Sorry! unable to allocate memory");

exit(0);

printf("Enter elements of array: ");

for(i=0;i<n;++i)

scanf("%d",ptr+i);

sum+=*(ptr+i);

printf("Sum=%d",sum);

free(ptr);

return 0;

}
// to check palindrome number

#include<conio.h>

#include<stdio.h>

void main()

int n,r,c,s=0;

printf("enetr any no"); //121

scanf("%d",&n);

c=n;

while(n>0)

r=n%10;

s=r+(s*10);

n=n/10;

if(c==s)

printf("palindrome no");

else

printf(" not");

}
// To calculate the length of string…

#include<stdio.h>

int main() {

char str[7];

int length;

printf("\nEnter the String : ");

gets(str);

length = 0; // Initial Length

while (str[length] != 0)

length++;

printf("\nLength of the String is : %d", length);

return(0);

You might also like