Verification of circular prime number
A circular prime number is a prime number 'p' with a property that all the number s got by cyclic permuting the digits of 'p', are also a prime number.
A number is said to be a prime number if it has no factors other than 1 and itself .19937 is a circular prime number , as all the numbers obtained by cyclic permuting the numbers-19937,99371,93719,37199,71993,19937 are all prime.
Develop an algorithm and write a C program to check if the number is circular prime or not.
input Format
A number
output number
Print Circular prime or Not circular prime.
C code-
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int n=0,i=0,l=0,c=0,j,pr,qw,rem=0;
char s[200],temp;
scanf("%d",&n);
while(n!=0) //counting =the number of digits and getting the digits in a list
{
s[i]=n%10;
n=n/10;
l++;
i++;
}
for(c=0;c<l;c++)
{
for(j=1;j<l;j++)
{
temp=s[j-1];
s[j-1]=s[j];
s[j]=temp;
}
for(i=l-1;i>=0;i--)
{
rem=rem*10+s[i];
}
for(pr=2;pr<rem;pr++)
{
if (rem%pr==0)
{
qw=1;
}
}
}
if(qw==1)
printf("Not circular prime");
if (qw==2)
printf("Circular prime");
}
basic pay and salary-
C code-
#include<stdio.h>
#include<string.h>
main()
{
int s,bp,da,n=0,id=0,hra;
char m[100];
scanf("%d",&n);
do{
scanf("%s%d%d%d%d",&m,&id,&bp,&da,&hra);
s=bp+((da*bp)/100)+hra;
printf("\n%d",id);
printf("\n%d",s);
n--;
}
while(n!=0);
}
Ques-Consider an nxn board game with four types of coins red, green, blue and yellow. Given the state of the board with coins in all cells, develop an algorithm and write a C program to check if the same coins are placed in the shape of ‘L’ on the board. The number of cells in the vertical and horizontal line of ‘L’ shape, is same. Red coins are represented by ‘r’, blue coins are represented by ‘b’, green coins are represented by ‘g’ and yellow coins are represented by ‘y’.
C code-
#include<stdio.h>
void main()
int i,j,n,max,num;
scanf("%d",n);
int a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<n;i++)
{
max=a[i][0];
for(j=0;j<n;j++)
{
if (a[i][j]>max)
max=a[i][j];
}
printf("%d\n",num);
}
}
row maximum-
ques-Given an nXn matrix with entries as numbers, print the maximum value in each row of the matrix.c code-
#include< stdio.h >
void main()
{
int i,j,n,max,num;
scanf("%d",&n);
for(i=0;i < n;i++)
{
max=-1;
for(j=0;j < n;j++)
{
scanf("%d",&num);
if(num > max)
max=num;
}
printf("%d\n",max);
}
}
void main()
{
int i,j,n,max,num;
scanf("%d",&n);
for(i=0;i < n;i++)
{
max=-1;
for(j=0;j < n;j++)
{
scanf("%d",&num);
if(num > max)
max=num;
}
printf("%d\n",max);
}
}
identify machines on same network
ques-Numeric addresses for computers on the international network, ‘Internet’ has four parts, separated by periods, of the form xxx.yyy.zzz.mmm where xxx , yyy , zzz , and mmm are positive integers. Locally, computers are usually known by a nickname as well.
Sample Data
IP address Name
111.22.3.44 platte
555.66.7.88 wabash
111.22.5.66 green
0.0.0.0 none
A pair of computers are said to be in same locality when the first two components of the addresses are same. Given the details of some computers, design an algorithm and write a C program to display a list of messages identifying each pair of computers from the same locality. In the messages, the computers should be identified by their nicknames. In this example, the message to be displayed will be Machines platte and green are on the same local network. For example, given IP address and nick name of machines as follows:
101.33.2.1 Atlas
101.33.56.80 Horizon
101.43.45.74 Pluto
101.33.56.80 Horizon
101.43.45.74 Pluto
Print ‘Machines Atlas and Horizon are on the same local network’.
#include< stdio.h >
#include< string.h >
void main()
{
int n,p,i,j;
char s[20][20],na[10][10];
scanf("%d",&n);
for(i=0;i < n;i++)
{
scanf("%s%s",s[i],na[i]);
p=0;
j=0;
while(p!=2)
{
j++;
if(s[i][j]=='.')
p++;
}
s[i][j]='\0';
}
for(i=0;i < n-1;i++)
for(j=i+1;j < n;j++)
if(strcmp(s[i],s[j])==0)
printf("Machines %s and %s are on the same local network",na[i],na[j]);
}
#include< stdio.h >
#include< string.h >
void main()
{
int n,p,i,j;
char s[20][20],na[10][10];
scanf("%d",&n);
for(i=0;i < n;i++)
{
scanf("%s%s",s[i],na[i]);
p=0;
j=0;
while(p!=2)
{
j++;
if(s[i][j]=='.')
p++;
}
s[i][j]='\0';
}
for(i=0;i < n-1;i++)
for(j=i+1;j < n;j++)
if(strcmp(s[i],s[j])==0)
printf("Machines %s and %s are on the same local network",na[i],na[j]);
}