
top of page


#include <stdio.h>
void main() {
int i=0;
int a[100];
int se=0,fe;
int na[5],cd,sn,n;
int count=0;
printf("\nEnter range of series : ");
scanf("%d",&n);
printf("\nEnter first element : ");
scanf("%d",&fe);
printf("\nEnter common difference : ");
scanf("%d",&cd);
for(i=0;i<n;i++)
{
a[i]=fe;
fe=fe+cd;
printf("---%d",a[i]);
}
printf("\nEnter element : ");
scanf("%d",&sn);
for(i=0;i<n;i++)
{
if(sn==a[i])
{
count=count+1;
printf("\n%d is present in series",sn);
}
}
if(count==0)
{
printf("\n%d is not present in series",sn);
}
}

#include <stdio.h>
void main() {
int n;
int choice;
int sum=0,i=1;
printf("\nEnter number : ");
scanf("%d",&n);
printf("\n1 : sum of %d numbers",n);
printf("\n2 : product of %d numbers",n);
printf("\n3 : check number is even");
printf("\n4 : check number is odd");
printf("\n5 : check number is prime");
printf("\n6 : factors of %d",n);
printf("\nEnter your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("\nSUM : %d",sum);
break;
}
case 2:
{
int product=1,i=1;
for(i=1;i<=n;i++)
{
product=product*i;
}
printf("\nPRODUCT : %d",product);
break;
}
case 3:
{
if(n%2==0)
{
printf("\n%d is even",n);
}
else
{
printf("\n%d is not even",n);
}
break;
}
case 4:
{
if(n%2==1)
{
printf("\n%d is odd",n);
}
else
{
printf("\n%d is not odd",n);
}
break;
}
case 5:
{
int count=0,i;
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count=count+1;
}
}
if(count==2)
{
printf("\n%d is prime",n);
}
else
{
printf("\n%d is not prime",n);
}
break;
}
case 6:
{
int count=0,i;
printf("Factors of %d : ",n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
printf(" %d",i);
}
}
break;
}
}
}
bottom of page

