Print prime numbers between 1-300 using break and continue in c
#include <math.h>
#include <math.h>
#include <stdio.h>
main(){
int i, j;
i = 2;
while ( i < 300 ){
j = 2;
while ( j < sqrt(i) ){
if ( i % j == 0 )
break;
else{
++j;
continue;
}
}
if ( j > sqrt(i) )
printf("%d\t", i);
++i;
}
return 0;
}
Pallindorem string
#include<string.h>
#include<stdio.h>
int main(){
char *str,*rev;
int i,j;
printf("\nEnter
a string:");
scanf("%s",str);
for(i=strlen(str)-1,j=0;i>=0;i--,j++)
rev[j]=str[i];
rev[j]='\0';
if(strcmp(rev,str))
printf("\nThe string is not a palindrome");
else
printf("\nThe string is a palindrome");
return 0;
}
Pallindorem string -2
#include
<stdio.h>
#include
<string.h>
int main()
{
char text[100];
int begin,
middle, end, length = 0;
gets(text);
while (
text[length] != '\0' )
length++;
end = length - 1;
middle =
length/2;
for( begin = 0 ;
begin < middle ; begin++ )
{
if (
text[begin] != text[end] )
{
printf("Not a palindrome.\n");
break;
}
end--;
}
if( begin ==
middle )
printf("Palindrome.\n");
return 0;
}
0 comments:
Post a Comment