Vous êtes sur la page 1sur 6

#include<stdio.h> #include<conio.

h> void main() { int n,s=0,m; clrscr(); printf("enter any no"); scanf("%d",&n); m=n; while(n>0) { r=n%10; s=s*10+r; n=n/10; } if(m==n)

printf("the no is palindrome");
else printf("no is not palindrome"); getch(); }

Write a C Program to join two strings? (eg. Input hari &123 output=hari123) ? int main() { char str1[10], str2[10]; printf("Enter the first string = "); scanf("%s", str1);

printf("Enter the second string = "); scanf("%s", str2); printf("Concatenation of two strings = %s", strcat(str1, str2)); return(0); }

-Write a program to find highest of five numbers entered by user?

int main() { int i, a[5], max;

printf("Enter the 5 numbers = ");


for (i=0; i<5; i++) scanf("%d", &a[i]); max = a[0]; for (i=1; i<5; i++) { if (max < a[i])

{
max = a[i]; } } printf("\nMaximum of 5 numbers = %d", max); return(0); }

-Enter a string & write a program to obtain reverse of string. Determine whether the original and reverse strings are equal?

int main() { char orgstr[10], revstr[10]; int i; printf("Enter a string = "); scanf("%s", str);

strcpy(revstr, orgstr);
for (i=0; i { char c = revstr[i]; revstr[i] = revstr[strlen(revstr)-i-1]; revstr[strlen(revstr)-i-1] = c; }

printf("\nReverse of the string = %s", revstr);


if (strcmp(orgstr, revstr) == 0) printf("The Original & Reverse strings are equal\n"); else printf("The Original & Reverse strings are not equal\n");

return(0); }

-Write a program to display Fibonacci series upto 70? int main() { int fibonacci(int n); int i; printf("Fibonacci Series upto 70 is :"); for (i=1; i<11; i++)

{
printf ("%d ", fibonacci(i)); } printf("\n"); return(0); }

int fibonacci(int n)
{ if (n == 1 n == 2) { return 1; } else

return fibonacci(n-1) + fibonacci(n-2); }

-Write a program to count number of words from a given sentence? int main() { char sentence[100]; int i, count = 0; printf("Enter a Sentence : \n"); gets(sentence); for (i=0; i {

if (isspace(sentence[i]))
{ count++; } } printf("Number of words in the sentence = %d", ++count); return(0);

-Write a program to interchange the contents two variables? int main() {

int a, b; int temp; printf("Enter value of a & b = "); scanf("%d %d", &a, &b); temp = a; a = b; b = temp; printf("\nValues of after interchanging a & b\n"); printf("a = %d b = %d\n\n", a, b);

return(0);

Vous aimerez peut-être aussi