0% found this document useful (0 votes)
17 views2 pages

#Include #Include Void Char Int Int: - CRT - Secure - No - Warnings

This document contains 3 C program code snippets. The first snippet counts the number of words in a user-input sentence by checking for spaces. The second snippet copies the first 5 characters of two user-input strings to each other. The third snippet checks if a user-input string is a palindrome by comparing the first and last characters and incrementally moving inward.

Uploaded by

Abdullah Abid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

#Include #Include Void Char Int Int: - CRT - Secure - No - Warnings

This document contains 3 C program code snippets. The first snippet counts the number of words in a user-input sentence by checking for spaces. The second snippet copies the first 5 characters of two user-input strings to each other. The third snippet checks if a user-input string is a palindrome by comparing the first and last characters and incrementally moving inward.

Uploaded by

Abdullah Abid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<string.h>
void main()
{
char x[100];
int count = 1;
int i, z;
printf("Enter the Sentence:\n");
gets(x);
z = strlen(x);
for (i = 0; i<z; i++)
{
if (x[i] ==' ')
{
count++;
}

}
printf("There are %d number of words in the sentence.\n", count);
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
void main()
{
char x[100];
char y[100];
char z[100];
printf("Enter the First String:\n");
gets(x);
printf("Enter the Second String:\n");
gets(y);
strncpy(z, x, 5);
strncpy(x, y, 5);
strncpy(y, z, 5);
printf("String 1=%s\n", x);
printf("String 2=%s\n", y);
}

#include<stdio.h>
#include<string.h>
int palin(char a[]);
void main()
{
char x[100];
printf("Enter the String:\n");
gets(x);
palin(x);
}
int palin(char a[])
{
int i=0, length, result=0;
length = strlen(a)-1;
while(length > i)
{
if (a[i++] != a[length--])
{
result = 1;
}
}
if (result == 0)
{
printf("String is Palindrome.\n");
}
else
{
printf("String is not Palindrome.\n");
}
}

You might also like