Вы находитесь на странице: 1из 15

Program 1- To check whether the inputed character is an alphabet or a digit or a special symbol.

#include <stdio.h> #include <conio.h> char char_is(char a); void main() { clrscr(); char ch,ct; printf("Enter a character= "); ch=getchar(); ct=char_is(ch); if(ct=='A') printf("It is an Alphabet."); else if(ct=='D') printf("It is a Digit."); else if(ct=='X') printf("It is a Special Character."); getch(); } /* Function Declaration to determine character type*/ char char_is(char a) { if((a>='a' && a<='z')||(a>='A' && a<='Z')) return ('A'); else if(a>='0'&&a<='9') return ('D'); else return ('X'); } OUTPUT:

Program 2- To read a line of text and count the number of vowels, consonants digits and blank spaces.

#include<stdio.h> #include<conio.h> void main() { clrscr(); char line[50],ch; int vow=0,con=0,dig=0,bs=0,count=0; printf("Enter a line of text:\n"); gets(line); for(;(ch=line[count])!='\0';count++) { if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') vow++; else if(ch>'A'&&ch<='Z'||ch>'a'&&ch<='z') con++; else if(ch>='0'&&ch<='9') dig++; else if(ch==' '||ch=='\t') bs++; } printf("\nNumber of vowels= %d",vow); printf("\nNumber of consonants= %d",con); printf("\nNumber of digits= %d",dig); printf("\nNumber of blank spaces= %d",bs); getch(); } OUTPUT:

Program 3-To print the inputted number of 2-3 digits in its word equivalent.

#include<stdio.h> #include<conio.h> void main() { long int num; int i,j,a,c[10],d[10],f=0; clrscr(); printf("Enter any 1-3 digit number= "); scanf("%ld",&num); printf("Word Equivalent= "); for(i=0;num!=0;num=num/10) { a=num%10; c[i]=a; f++; d[i]=f; i++; } for(i;i>=0;i--) { if(d[i]==3) { switch(c[i]) { case 1: printf("One Hundred "); break; case 2: printf("Two Hundred "); break; case 3: printf("Three Hundred "); break; case 4: printf("Four Hundred "); break; case 5: printf("Five Hundred "); break; case 6: printf("Six Hundred "); break; case 7: printf("Seven Hundred "); break; case 8: printf("Eight Hundred "); break; case 9: printf("Nine Hundred "); break; } } else if(d[i]==2) { switch(c[i]) { case 0: break; case 2: printf("Twenty "); break;

case 3: printf("Thirty "); break; case 4: printf("Fourty "); break; case 5: printf("Fifty "); break; case 6: printf("Sixty "); break; case 7: printf("Seventy "); break; case 8: printf("Eighty "); break; case 9: printf("Ninety "); break; } } else if(d[i]==1) { switch(c[i]) { case 1: printf("One "); break; case 2: printf("Two "); break; case 3: printf("Three "); break; case 4: printf("Four "); break; case 5: printf("Five "); break; case 6: printf("Six "); break; case 7: printf("Seven "); break; case 8: printf("Eight "); break; case 9: printf("Nine "); break; } } else if(c[1]==1) { switch(c[0]) { case 0: printf("Ten "); break; case 1: printf("Eleven "); break; case 2: printf("Twelve "); break; case 3: printf("Thirteen "); break; case 4: printf("Fourteen "); break; case 5: printf("Fifteen "); break; case 6: printf("Sixteen "); break; case 7: printf("Seventeen "); break; case 8: printf("Eighteen "); break; case 9: printf("Nineteen "); break; } } } getch(); }

OUTPUT:

Program 4- To check the inputted word for palindrome.

#include<stdio.h> #include<conio.h> void main() { clrscr(); char strg[10],k[10]; int i,f=0; printf("enter any word= "); scanf("%s",strg); for(i=0;strg[i]!='\0';i++) k[i]=strg[i]; for(i;i>=0;i--) { if(strg[i]!=k[i]) { printf("the word is not a palindrome\n"); f++; break; } } if(f==0) printf("the word is palindrome\n"); getch(); } OUTPUT:

Program 5- To generate the following alphabetical pattern.

A A A A A A A

B B B B B B

C C C C C

D D D D

E E E

F F

F F

E E E

D D D D

C C C C C

B B B B B B

A A A A A A A

#include<stdio.h> #include<conio.h> void main() { clrscr(); int n,i,j,x=13,y=1; for(i=7;i>=1;i--) { n='A'; for(j=i;j>=1;j--) { printf(" %c",n); n=n+1; } gotoxy(x,y); for(j=n-1;j>='A';j--) { printf(" %c",j); } x=x+2; y++; printf("\n"); } getch(); }

Output:

Program 6- To reverse the inputted string.

#include<stdio.h> #include<conio.h> void main() { clrscr(); char str[100]; register int i; printf("enter any string= "); scanf("%s",str); for(i=0;str[i]!='\0';i++) str[i]; printf("the reverse string is= "); for(;i>=0;i--) printf("%c",str[i]); getch(); } OUTPUT:

Program 7- To enter marks of 10 students and finding the division of each student with the help of structure.

#include<stdio.h> #include<conio.h> struct stu { int h,e,m,s,c; long int rn; float sum; float per; }; stu s[10]; void main() { clrscr(); int i,n; s: printf("Enter the number of students= "); scanf("%d",&n); if(n>10) { printf("Too many records to enter. Try again\n"); goto s; } printf("Enter the Roll Number & Marks of each student.\n"); for(i=0;i<n;i++) scanf("%ld%d%d%d%d%d",&s[i].rn,&s[i].h,&s[i].e,&s[i].m,&s[i].s,&s[i].c); printf("\nThe Student Record is as follows:\n\n"); printf("Roll No. MARKS\n"); printf(" Hindi English Maths Science Computer Percent Division\n"); for(i=0;i<n;i++) { printf("---------------------------------------------------------------------\n"); s[i].sum=s[i].h+s[i].e+s[i].m+s[i].s+s[i].c; s[i].per=(s[i].sum)/5; printf("%4ld %9d %6d %7d %7d %8d %5.2f ",s[i].rn,s[i].h,s[i].e,s[i].m,s[i].s,s[i].c,s[i].per); if(s[i].per>=(60.0)) printf(" FIRST\n"); else if(s[i].per>=(50.0)&&s[i].per<60) printf(" SECOND\n"); else if(s[i].per>=40&&s[i].per<50) printf(" THIRD\n");

else if(s[i].per<40) printf(" FAIL\n"); } getch(); } OUTPUT:

Program 8- To print the number of vowels in a set of string.

#include<stdio.h> #include<conio.h> void main() { char str[25]; int i,j,vow_cont=0,n,count; printf("Enter the number of Strings= "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("Enter the string %d: ",i); scanf("%s",str); vow_cont=0; for(count=0;str[count]!='\0';count++) { if(str[count]=='a'||str[count]=='e'||str[count]=='i'||str[count]=='o'||str[count]=='u') vow_cont+=1; } printf("The number of vowels in string %d= %d\n",i,vow_cont); } getch(); }

OUTPUT:

Program 9- To sort the inputted names in ascending order.

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char name[20][20],temp[20]; int num,i,j,result,index; clrscr(); printf("Enter the number of names in the list(Max 20): "); scanf("%d",&num); printf("Enter the names:\n"); for(i=0;i<num;i++) scanf("%s",name[i]); for(i=0;i<num;i++) { index=i; for(j=i+1;j<num;j++) { result=strcmp(name[index],name[j]); //Logic for sorting if(result>0) index=j; } strcpy(temp,name[index]); strcpy(name[index],name[i]); //Logic to Swap strings using string functions. strcpy(name[i],temp); } printf("\n\n\nThe sorted list is:\n\n"); for(i=0;i<num;i++) printf("%s\n",name[i]); } Output:

Program 10- To check the inputted name in a list of names stored in string array.
#include<stdio.h> #include<conio.h> #include<string.h> #define FOUND 1 #define NOTFOUND 0 void main() { char masterlist*6+*10+=,akshay,parag,raman,srinivas,gopal,rajesh-; int I,flag,a; char yourname[10]; printf(Enter Your Name:); scanf(%s,yourname); flag=NOTFOUND; for(i=0;i<=5;i++) { a=strcmp(&masterlist[i][10],yourname); if(a==0) { printf(Welcome, you can enter the palace\n); flag=FOUND; break; } } if(flag==NOTFOUND) printf(Sorry, you are atresspasser\n); } Output:

Вам также может понравиться