Generate all the prime numbers between 1 and n
#include
#include
void main()
{
int no,counter,counter1,check;
clrscr();
printf(“<———————–Prime no. series————————>”);
printf(“\n\n\n\t\t\tInput the value of n: “);
scanf(“%d”,&no);
printf(“\n\nThe prime no. series b/w 1 to %d : \n\n”,no);
{
int no,counter,counter1,check;
clrscr();
printf(“<———————–Prime no. series————————>”);
printf(“\n\n\n\t\t\tInput the value of n: “);
scanf(“%d”,&no);
printf(“\n\nThe prime no. series b/w 1 to %d : \n\n”,no);
for(counter = 1; counter <= no; counter++)
{
check = 0;
for(counter1 = counter-1; counter1 > 1 ; counter1–)
if(counter%counter1 == 0)
{
check++;
break;
}
if(check == 0)
printf(“%d\t”,counter);
}
getch();
}
{
check = 0;
for(counter1 = counter-1; counter1 > 1 ; counter1–)
if(counter%counter1 == 0)
{
check++;
break;
}
if(check == 0)
printf(“%d\t”,counter);
}
getch();
}
Find the
sum of individual digits of a positive integer
#include
#include
void main()
{
int num, k=1, sum=0;
clrscr();
printf(“Enter the number whose digits are to be added:”);
scanf(“%d”,&num);
while(num!=0)
{
k=num%10;
sum=sum+k;
k=num/10;
num=k;
}
printf(“Sum of the digits:%d”,sum);
getch();
}
#include
void main()
{
int num, k=1, sum=0;
clrscr();
printf(“Enter the number whose digits are to be added:”);
scanf(“%d”,&num);
while(num!=0)
{
k=num%10;
sum=sum+k;
k=num/10;
num=k;
}
printf(“Sum of the digits:%d”,sum);
getch();
}
Write a c
program to find prime numbers
#include
#include
void main()
{
int i,j=2,ch=0;
clrscr();
printf("\nEnter any number");
scanf("%d",&i);
while(j<=i/2)
{
if(i%j==0)
{
printf("%d Is not prime",i);
ch=1;
break;
}
else
{
j++;
}
}
if(ch==0)
{
printf("%d Is prime",i);
}
}
{
int i,j=2,ch=0;
clrscr();
printf("\nEnter any number");
scanf("%d",&i);
while(j<=i/2)
{
if(i%j==0)
{
printf("%d Is not prime",i);
ch=1;
break;
}
else
{
j++;
}
}
if(ch==0)
{
printf("%d Is prime",i);
}
}
Find both
the largest and smallest number in a list of integers
#include
#include
void main( )
{
float largest(float a[ ], int n);
float value[4] = {2.5,-4.75,1.2,3.67};
printf(“%f\n”, largest(value,4));
}
float largest(float a[], int n)
{
int i;
float max;
max = a[0];
for(i = 1; i < n; i++)
if(max < a[i])
max = a[i];
return(max);
}
{
float largest(float a[ ], int n);
float value[4] = {2.5,-4.75,1.2,3.67};
printf(“%f\n”, largest(value,4));
}
float largest(float a[], int n)
{
int i;
float max;
max = a[0];
for(i = 1; i < n; i++)
if(max < a[i])
max = a[i];
return(max);
}
Whether the given no. is palindrome or not
#include
#include
void main()
{
int n,r,t,sum=0;
clrscr();
printf(" Output:\n");
printf("\tEnter a no.");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
if(sum==t)
printf("\tThe no. %d is a pallindrome",t);
else
printf("\tThe no. %d is not a pallindrome",t);
getch();
}
#include
void main()
{
int n,r,t,sum=0;
clrscr();
printf(" Output:\n");
printf("\tEnter a no.");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}
if(sum==t)
printf("\tThe no. %d is a pallindrome",t);
else
printf("\tThe no. %d is not a pallindrome",t);
getch();
}
Whether the given no.is
armstrong or not
#include
#include
void main()
{
int n,r,t,sum=0;
clrscr();
printf(" Output :\n");
printf("\tEnter a no.");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==t)
printf("The no. %d is armstrong",t);
else
printf("The no. %d is not an armstrong",t);
getch();
}
#include
void main()
{
int n,r,t,sum=0;
clrscr();
printf(" Output :\n");
printf("\tEnter a no.");
scanf("%d",&n);
t=n;
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==t)
printf("The no. %d is armstrong",t);
else
printf("The no. %d is not an armstrong",t);
getch();
}
No comments:
Post a Comment