28
PROGRAMS IN GET CERTIFIED Spell Bee #include <stdio.h> #include <string.h> #include <math.h> #include<ctype.h> int main(void) { char s[10],st[10]; int l1,l2,i=0,cnt=0,l=0,cas=0; scanf("%s",s); scanf("%s",st); while(st[i]!='\0' ) { if(islower(st[i])) return 0; else i++; } i=0; while(s[i]=='\0') { if(islower(s[i])) return 0; else i++; D.U. 1

Get Certified

  • Upload
    neha

  • View
    226

  • Download
    1

Embed Size (px)

DESCRIPTION

Cognizant Get certify

Citation preview

Page 1: Get Certified

PROGRAMS IN GET CERTIFIEDSpell Bee#include <stdio.h>

#include <string.h>

#include <math.h>

#include<ctype.h>

int main(void) {

char s[10],st[10];

int l1,l2,i=0,cnt=0,l=0,cas=0;

scanf("%s",s);

scanf("%s",st);

while(st[i]!='\0' )

{

if(islower(st[i]))

return 0;

else i++;

}

i=0;

while(s[i]=='\0')

{

if(islower(s[i]))

return 0;

else i++;

}

l1=strlen(s);

l2=strlen(st);

l=abs(l1-l2);

D.U. 1

Page 2: Get Certified

while(s[i]!='\0' && st[i]!= '\0')

{

if((s[i]>='A' && s[i]<='Z')&&(st[i]>='A' && st[i]<='Z'))

{

if(s[i]!=st[i])

cnt++;

i++;

}

else

{

cas=1;

break;

}

}

if(cas==1)

{}

else if (cas==0)

{

cnt+=l;

if(cnt==0)

printf("%s IS CORRECT",st);

else if(cnt>0 && cnt<=2)

printf("%s IS ALMOST CORRECT",st);

else

printf("%s IS WRONG",st);

}

return 0;

}

D.U. 2

Page 3: Get Certified

Letter based Gift Selection# include <ctype.h>#include<process.h>#include<stdio.h>int main(){char a[20],b[20],c[20];char c1;gets(a);gets(b);gets(c);scanf("%c",&c1);for(i=0;a[i]!=NULL;i++)if(islower(a[i]));exit(0);for(i=0;b[i]!=NULL;i++)if(islower(b[i]));exit(0);for(i=0;c[i]!=NULL;i++)if(islower(c[i]));exit(0);If(islower(c1))exit(0);if(a[0]==c1||b[0]==c1||c[0]==c1)printf("yes");elseprintf("no");return 0;}

Counting number of words in a sting (including spaces)#include<stdio.h>

#include<string.h>

int main()

{

char str[50];

int i,n, flag=0,count=0;

gets(str);

D.U. 3

Page 4: Get Certified

n=strlen(str);

for(i=0;i<n;i++)

{

if(str[i]==' '||(str[i]>='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')||(str[i]>='0'&&str[i]<='9'))

count++;

else

flag=1;

}

if(flag==0)

printf("%d",count);

else

printf("Invalid Input");

return 0;

}

Armstrong number detection#include <stdio.h>

int main() {

int n, n1, rem, num=0,flag=0;

scanf("%d", &n);

if(n<0)

printf("%d is a negative number",n);

else

{

n1=n;

while(n1!=0)

{

rem=n1%10;

num+=rem*rem*rem;

D.U. 4

Page 5: Get Certified

n1/=10;

}

if(num==n)

printf("%d is an Armstrong number.",n);

else printf("%d is not an Armstrong number.",n);

}

return 0;

}

Zero Duplicate# include  <stdio.h>

int main(void) {int a[100],i,j,f,n;scanf("%d",&n);for(i=0;i<n;i++){scanf("%d",&a[i]);}for(i=0;i<n;i++){for(j=0;j<n;j++){if(a[i]==a[j] && i!=j && a[j]!=0){a[j]=0;}}}for(i=0;i<n;i++)printf("%d ",a[i]);

return 0;

}

D.U. 5

Page 6: Get Certified

Sum of odd digits in a number#include <stdio.h>

int main(void)

{

int n,s,d;

scanf("%d",&n);

while(n>0)

{

d=n%10;

if(d%2==1)

s+=d;

n/=10;

}

printf("%d",s);

return 0;

}

Generate new number#include<stdio.h>

int main()

{

int n,a[3],num,i=0,count;

scanf("%d",&n);

num=n;

while(num>0)

{

a[i]=num%10;

num/=10;

D.U. 6

Page 7: Get Certified

i++;

count++;

}

if(n<0 ||count!=3)

printf("Invalid Input");

else

{

n=a[1]*100+a[0]*10+a[2];

printf("%d",n);

}

return 0;

}

Count the number of even and odd integers#include<studio.h>#include<conio.h>main(){int a[15],count_even=0,count_odd=0,i;

for(i=0;i<n;i++){scanf("%d",&a[i]);

If(a[i]<0)

return 0;

}for(i=0;i<n;i++){if((a[i]%2 ==0))count_even++;if((a[i]%2==1))count_odd++;}printf("%d %d",count_even,count_odd);

D.U. 7

Page 8: Get Certified

getch();}

Count the number of even#include<studio.h>#include<conio.h>main(){int a[15],count_even=0,i;for(i=0;i<n;i++)

{scanf("%d",&a[i]);

If(a[i]<0)

return 0;}

for(i=0;i<n;i++){if((a[i]%2 ==0))count_even++;}printf("%d",count_even);getch();}Sum of the cubes of first N natural numbers#include <stdio.h>  int main() {        int num, cube, sum = 0, i = 1;        printf("Enter the value for n:");        scanf("%d", &num);        while (i <= num) {                cube = i * i * i;                sum = sum + cube;                i++;        }        printf("Sum of cubes of first %d natural"                        " numbers is %d\n", num, sum);

        return 0;  }

Prime Factors

D.U. 8

Page 9: Get Certified

#include <stdio.h>

int main(void) {

int n,i,j,a[50],p=0,temp=0;

scanf("%d",&n);

if(n>0)

{

for(i=2;i<=n;i++)

{temp=0;

if(n%i==0)

{

for(j=2;j<=i/2;j++)

{

if(i%j==0)

{temp=1;

break;

}

}

if(temp==0)

{

a[p]=i;

p++;

}

}

}

for(i=0;i<p-1;i++)

{

for(j=0;j<p-i-1;j++)

D.U. 9

Page 10: Get Certified

{

if(a[j]<a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

} }

}

for(i=0;i<p;i++)

printf("%d \n",a[i]);

}

return 0;

}

Sum of the Squares of Even numbers.# include <stdio.h>int main(){int n,sum=0,i;scanf("%d",&n);if(n<0){printf("%d is negative number\n",n);

}else if(n>15){ printf("%d is greater than 15",n);

}else{ for(i=2;i<=n;i=i+2){

D.U. 10

Page 11: Get Certified

sum=sum+i*i;}}printf("%d",sum);}return 0;}

ELECTRICITY BILL

#include <stdio.h>

#include <string.h>

int main(void) {

char input1[50],input2[50];

int input3,bill=0,output,l1,l2,n1=0,n2=0,i;

scanf("%s",input1);

scanf("%s",input2);

scanf("%d",&input3);

l1=strlen(input1);

l2=strlen(input2);

for (i=5;i<l1;i++)

{

n1=n1*10+(input1[i]-48);

}

for (i=5;i<l2;i++)

{

n2=n2*10+(input2[i]-48);

}

if((n1<n2)

bill=-(n1-n2)*input3;

D.U. 11

Page 12: Get Certified

else

bill=(n1-n2)*input3;

printf("%d",bill);

return 0;

}

DIGITAL ROOTS

#include <stdio.h>

int main(void) {

int n,s,d;

scanf("%d",&n);

if(n>=0 &7 n<=32676)

{

while(n>10)

{

d=n%10;

s+=d;

n/=10;

if(n<10)

{

n+=s;

s=0;

}}

printf("%d",n);

}

return 0;

}

D.U. 12

Page 13: Get Certified

COUNT REPEATED VALUES IN AN INTEGER ARRAY

#include <stdio.h>

int main(void) {

int a[10],p=0,n,i,f=0,j,t=0;

scanf("%d",&n);

for(i=0;i<n;i++)

{

scanf("%d",&a[i]);

if(a[i]<0)

{

t=1;

break;}

}

if(t==1 || n<0)

printf("Invalid Input");

else

{

for(i=0;i<n;i++)

{

f=1;

for(j=0;j<n;j++)

{

if(a[i]==a[j] && i!=j && a[j]!=-1)

{

a[j]=-1;

f++;

}}

if(f>1)

D.U. 13

Page 14: Get Certified

{

p++;

}}

printf("%d",p);

}

return 0;

}

PASSWORD

#include<stdio.h>

#include<string.h>

int lenthFunction(char arr[])

{

return strlen(arr);

}

int specialcharacter(char arr[])

{int i,flag=2,count=0;

for(i=0;i<strlen(arr);i++)

{

if(arr[i]=='@' || arr[i]=='_' || arr[i]=='#')

{

count++;

if(count==1)

{

flag=0;

}

else

{

flag=1;

}}}

D.U. 14

Page 15: Get Certified

return flag;

}

int main()

{

char password[20];

gets(password);

if(lenthFunction(password)<8)

{

printf("Invalid");

}

else if(specialcharacter(password)!=0)

{

printf("Invalid");

}

else if((password[0]>'0' && password[0]<'9')||(password[0]>=33 && password[0]<=64)|| (password[0]>=123 && password[0]<=255 ))

{

printf("Invalid");

}

else if((password[strlen(password)-1]>=33 && password[strlen(password)-1]<=64)&& (password[strlen(password)-1]>=123 && password[strlen(password)-1]<=255 ))

{

printf("Invalid");

}

else

{

printf("Valid");

}

return 0;

}

D.U. 15

Page 16: Get Certified

SECOND MAXIMUM

#include <stdio.h>

int main()

{

int a[50],i,j,s,temp=0;

scanf("%d",&s);

for(i=0;i<s;i++)

scanf("%d",&a[i]);

for(i=0;i<s-1;i++)

{

for(j=0;j<s-i-1;j++)

{

if(a[j]<a[j+1])

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

printf("%d",a[1]);

return 0;

}

STUDENT FEE

#include <stdio.h>

int main()

{

D.U. 16

Page 17: Get Certified

int f,m;

scanf("%d",&f);

scanf("%d",&m);

if(f>=0 && m >=0 && m<=100 && f<=32767)

{

if(m>90)

f=f-f*50/100;

else if(f>=80 && f<=90)

f=f-f*25/100;

else if(f>=70 && f<=79)

f=f-f*10/100;

printf("%d",f);

}

else

printf("Invalid Input");

return 0;

}

SUM OF THE SQAURE OF THE DIGIT

#include <stdio.h>

int main()

{

int n,d=0,s=0;

scanf("%d",&n);

if(n>=0 && n<=32767)

{

D.U. 17

Page 18: Get Certified

while(n>0)

{

d=n%10;

s+=d;

n/=10;

}

printf("%d",s);

}

return 0;

}

DATE

#include <stdio.h>

#include<string.h>

char *m[12]={"01","02","03","04","05","06","07","08","09","10","11","12"};

int dd[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(void)

{

char d[10],mon[3];

int i,n,l,d1,year,mo=0,temp=0;

scanf("%d",&n);

scanf("%s",d);

l=strlen(d);

mon[0]=d[0];

mon[1]=d[1];

mon[2]='\0';

year=(d[6]-48)*1000+(d[7]-48)*100+(d[8]-48)*10+(d[9]-48);

if((year%4==0 && year%100!=0) || (year%400==0))

dd[1]=29;

D.U. 18

Page 19: Get Certified

d1=(d[3]-48)*10+(d[4]-48);

for(i=0;i<12;i++)

{

if((strcmp(mon,m[i])==0))

{

break;

}}

if(i==12)

temp=1;

if(temp==0)

{

mo=(d[0]-48)*10+(d[1]-48);

if(!(d1>=1 && d1<=dd[mo-1]))

temp=1;

}

if(temp==0)

{

if(l<10 || n<0)

temp=1;

}

if(temp==0)

{

if(!(d[2]=='/' && d[5]=='/'))

temp=1;

}

if(temp==0)

{

D.U. 19

Page 20: Get Certified

for(i=0;i<l;i++)

{

if(i!=2 && i!=5)

{

if(!(d[i]>=48 && d[i]<=57) )

{

temp=1;

break;

}}}}

if(temp==0)

{

year=(d[6]-48)*1000+(d[7]-48)*100+(d[8]-48)*10+(d[9]-48);

for(i=0;i<6;i++)

printf("%c",d[i]);

printf("%d",(year+n));

}

if(temp==1)

printf("Invalid Year");

return 0;

}

Foo Fighter#include <string.h>

#include <stdio.h>

int main() {

char st[256];

int l,i,temp=0,j,cnt=0;

D.U. 20

Page 21: Get Certified

gets(st);

l=strlen(st);

for(i=0;i<l;i++) {

if(!(st[i]>='A' && st[i]<='Z'))

{

return 0;

}

}

if(temp==0) {

for(i=0;i<=l-3;i++)

{

if(st[i]=='F' && st[i+1]=='O' && st[i+2]=='O')

{

cnt++;

} }

for(j=1;j<=cnt;j++)

{

for(i=0;i<=l-3;i++)

{

if(st[i]=='F' && st[i+1]=='O' && st[i+2]=='O')

{

st[i]='O'; st[i+1]='O';

st[i+2]='F';

} }}

printf("%s",st);

}

return 0;

}

D.U. 21

Page 22: Get Certified

[ Input : 100 20 Output: 300 (sum of 20, 40, 60, 80, 100) ] . . . . WAP to input limit L and the number N & output the sum by multiplying each time by its own until it reaches upto limit.

#include <stdio.h>

void add(int,int,int,int);

int main(void) {

int l=0,n,num,s=0;

scanf("%d",&l);

scanf("%d",&n);

num=n;

while(n<=l) {

s=s+n; n+=num;

}

printf("%d",s);

return 0;

}

D.U. 22

Page 23: Get Certified

Daily Allowances

D.U. 23

Page 24: Get Certified

Write a program to sum of the numbers till the limit L that are divisible by number 'n'. Print 'Invalid Input' if L is negative.

#include <stdio.h>

void add(int,int,int,int);

int main() {

int l=0,n,i,s=0;

scanf("%d",&l);

scanf("%d",&n);

for(i=1;i<=l;i++) { if(i%n==0)

s+=i;

}

printf("%d",s);

return 0;

}

D.U. 24