Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Standard view
Full view
of .
×
0 of .
Results for:
P. 1
Simple c Programs

# Simple c Programs

Ratings: 0|Views: 460|Likes:
THESE R SIMPLE C- PROGRAMS
THESE R SIMPLE C- PROGRAMS

### Availability:

See More
See less

03/09/2011

pdf

text

original

/* Assignment : 01*//*Program To Find Roots Of The Quadratic Equation Using SwitchCase.*/
#include<stdio.h>#include<conio.h>#include<math.h>void main(){float a,b,c,d,r,r1,r2,real,img;int ch;clrscr(); printf("\n\nEnter The Coefficients Of a,b & c:\t");scanf("%f%f%f",&a,&b,&c);if(a==0){r=-b/c; printf("\nRoot=%f",r); printf("\n\nIt Is A Linear Equation.\n");}else{d=b*b-4*a*c;if(d==0)ch=1;else if(d>0)ch=2;elsech=3;switch(ch){case 1: printf("\nRoots Are Equal.\n");r1=-b/(2*a);r2=r1; printf("\nRoot1 = %.2f,\nRoot2 = %.2f.",r1,r2); break;case 2: printf("\nRoots Are Real & Distinct.\n");r1=-b+sqrt(d)/(2*a);r2=-b-sqrt(d)/(2*a); printf("\nRoot1 = %f,\nRoot2 = %f.",r1,r2); break;case 3: printf("\nRoots Are Complex.\n");real=-b/(2*a);img=(sqrt(abs(d)))/(2*a); printf("\nRoot1= %.2f+%.2fi,\n",real,img); printf("\nRoot2= %.2f-%.2fi.",real,img); break;default:printf("\nInvalid Choice.");

}}getch();}
/* Output*/
Enter The Coefficients Of a,b & c: 0 2 3Root=-0.666667It Is A Linear Equation.Enter The Coefficients Of a,b & c: 1 2 3Roots Are Complex.Root1= -1.00+1.41i,Root2= -1.00-1.41i.Enter The Coefficients Of a,b & c: 8 12 0Roots Are Real & Distinct.Root1 = -11.250000,Root2 = -12.750000.Enter The Coefficients Of a,b & c: 8 12 0Roots Are Real & Distinct.Root1 = -11.250000,Root2 = -12.750000.

/* Assignment : 02*//*Program To Find The Number Of Vowels,Consonants,SpecialCharacter & White Spaces In Given String.*/
#include<stdio.h>#include<conio.h>#include<string.h>void main(){int i,v=0,c=0,len=0,sp=0,wh=0;char str[50];clrscr(); printf("\nEnter The String.\t");gets(str);len=strlen(str);for(i=0;i<len;i++){str[i]=tolower(str[i]);if(str[i]>='a' && str[i]<='z'){if(str[i]=='a' || str[i]=='e' ||str[i]=='i' ||str[i]=='o' ||str[i]=='u')v++;elsec++;}else if((str[i]==' ') || (str[i]=='\t'))wh++;elsesp++;} printf("\n\nNumber Of Vowels : %d",v); printf("\n\nNumber Of Consonants : %d",c); printf("\n\nNumber Of White Spaces : %d",wh); printf("\n\nNumber Of Special Characters : %d",sp);getch();}

## Activity (4)

### Showing

AllMost RecentReviewsAll NotesLikes