Program 1 - Excess number
#include<stdio.h>
int main()
{
int n,s=0,c=0,*a,i,j;
scanf("%d",&n);
a=(int*)malloc(n*sizeof(n));
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
{
s=0;
c=0;
for(j=i+1;j<n;j++)
{
s+=a[j];
c++;
}
s=s/c;
if(a[i]>s)
printf("%d\n",a[i]);
}
printf("%d",a[n-1]);
}
Program 2 - Count of 2 digit prime numbers
#include<stdio.h>
#include<string.h>
int prime(int n)
{
int f=0,i;
for(i=2;i<=n/2;i++)
if(n%i==0)
{
f=1;
break;
}
return f;
}
int main()
{
char a[10];
int i,c=0,n,f;
scanf("%[^\n]",&a);
for(i=0;i<strlen(a)-1;i++)
{
n=((int)(a[i])-48)*10+(int)(a[i+1])-48;
if(prime(n)==0)
c++;
}
printf("%d",c);
}
Program 3 - Singular to Plural
#include<stdio.h>
#include<string.h>
int main()
{
char a[10];
int l;
scanf("%[^\n]",&a);
l=strlen(a);
if(a[l-1]=='y')
{
a[l-1]='\0';
strcat(a,"ies");
}
else if((a[l-1]=='s') || ((a[l-1]=='h')&&((a[l-2]=='c') || (a[l-2]=='s'))))
strcat(a,"es");
else
strcat(a,"s");
printf("%s",a);
}
Program 4 - Local Network
#include<stdio.h>
int main()
{
int n,i,j;
char a[5][20],b[5][8];
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",&a[i]);
for(j=0;a[i][j-1]!='.';j++)
b[i][j]=a[i][j];
for(j=j;a[i][j]!='.';j++)
b[i][j]=a[i][j];
b[i][j]='\0';
}
for(i=0;i<n;i++)
printf("%s\n",b[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(strcmp(b[i],b[j])==0)
printf("Machines %d and %d are on the same local network",i+1,j+1);
}
Program 5 - L Shape
#include<stdio.h>
#include<stdlib.h>
int main()
{
int r,c,i,j,m,n;
char a[10][10];
scanf("%d%d",&r,&c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf(" %c",&a[i][j]);
for(i=0;i<r-1;i++)
for(j=0;j<c-2;j++)
{
int c1=0,c2=0;
m=i;
while(a[m][j]==a[++m][j])
c1++;
n=j+1;
if(c1>0)
while(a[m-1][n]==a[m-1][++n])
c2++;
if((c1==c2)&&(c1!=0))
{
printf("Yes");
exit(0);
}
}
printf("No");
}
Try my app on play store and rate it!
No comments:
Post a Comment