Posts

Showing posts from June, 2015

List all the Prime Numbers

#include<stdio.h> void main() { int n,i,j,flag; printf("\n\nEnter the limit\t:"); scanf("%d",&n); printf("\nThe prime numbers within the given limit:\n"); for(i=1;i { flag=0; for(j=2;j { if(i%j==0) { flag=1; break; } } if(flag==0) printf("%d\t",i); } } Output   Print   Download Code Output Enter the limit :60 The prime numbers within the given limit: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59

Solve Quadratic Equation

#include <stdio.h> #include <math.h> void main() { float a,b,c,d,temp,r1,r2; printf("\nEnter the value of a\t:"); scanf("%f",&a); printf("Enter the value of b\t:"); scanf("%f",&b); printf("Enter the value of c\t:"); scanf("%f",&c); d=((b*b)-(4*c*a)); if(d==0) { printf("\nRoots are real and equal\n"); r1=-b/(2*a); printf("\t X1=%f \n \t X2=%f ", r1, r1 ); } else if(d>0) { printf("\nRoots are real and distinct\n"); temp=sqrt(d); r1=(-b+temp)/(2*a); r2=(-b-temp)/(2*a); printf("\n\tX1=%f\n\tX2=%f",r1,r2); } else { printf("\nRoots are Imaginary\n"); d*=-1; temp=sqrt(d); r1=-b/(2*a); r2=temp/(2*a); printf("\n\tX1=(%f + %fi)\n\tX2=(%f - %fi)",r1,r2,r1,r2); } } Output   Print   Download Code Output Enter the value of a :1 Enter the value of b :-11 Enter the value of c :30 Roots are real and d...

Find the greatest of two numbers using Conditional Operator

#include<stdio.h> void main() { int n1,n2,g; printf("Enter Numbers (n1, n2) : "); scanf("%d %d",&n1,&n2); g=n1>n2?n1:n2; printf("Greatest=%d",g); } Output   Print   Download Code Output Enter Numbers (n1, n2) : 5 6 Greatest=6

Generate the Fibonacci Series

#include<stdio.h> void main() { int t,i,m=0,n=1,f=1; printf("\n\nEnter the number of terms:"); scanf("%d",&t); printf("\n The Fibonacci Series of %d terms:\n",t); for(i=1;i { printf("%d\t",f); f=m+n; m=n; n=f; } } Output   Print   Download Code Output Enter the number of terms:10 The Fibonacci Series of 10 terms: 1 1 2 3 5 8 13 21 34 55

Print 1-10 using do-while loop

#include<stdio.h> void main() { int i=1; do{ printf("%d\n",i); i++; }while(i=100); } Output   Print   Download Code Output 1 2 3 4 5 6 7 8 9 10

Find the perimeter of a Circle

#include <stdio.h> void main() { int r; float pi=3.14; r=7; printf("Perimeter=%f",2*pi*r); } Output   Print   Download Code Output Perimeter=43.960003

Check whether an alphabet is Vowel or not

#include <stdio.h> void main() { char in; printf("Enter Character: "); scanf("%c", &in); if(in>=65&&in<=90 || in>=97&& in<=122) { if(in<97) in=in+32; if(in=='a'||in=='e'||in=='i'||in=='o'||in=='u') printf("vowel"); else printf("consonent"); } else printf("Not an valid Alphabet"); } Output   Print   Download Code Output Enter Character: A vowel

Print the ASCII values of all the English Alphabets

#include<stdio.h> void main() { char chl='a'; char chu='A'; int i; printf("\n==========================="); for(i=1;i<=26;i++,chu++,chl++) printf("\n|%c | %d \t|| %c| %d |",chl,chl, chu, chu); printf("\n==========================="); } Output   Print   Download Code Output =========================== |a | 97 || A| 65 | |b | 98 || B| 66 | |c | 99 || C| 67 | |d | 100 || D| 68 | |e | 101 || E| 69 | |f | 102 || F| 70 | |g | 103 || G| 71 | |h | 104 || H| 72 | |i | 105 || I| 73 | |j | 106 || J| 74 | |k | 107 || K| 75 | |l | 108 || L| 76 | |m | 109 || M| 77 | |n | 110 || N| 78 | |o | 111 || O| 79 | |p | 112 || P| 80 | |q | 113 || Q| 81 | |r | 114 || R| 82 | |s | 115 || S| 83 | |t | 116 || T| 84 | |u | 117 || U| 85 | |v | 118 || V| 86 | |w | 119 ...

Find Area and Circumference of a Circle

#include<stdio.h> #define PI 3.142 void main() { float r,a,c; printf("\nEnter the radius of circle:\t"); scanf("%f",&r); a=PI*r*r; printf("\nThe area of the circle:\t%f",a); c=2*PI*r; printf("\nThe circumference of the circle: %f",c); } Output   Print   Download Code Output Enter the radius of circle: 2 The area of the circle: 12.568000 The circumference of the circle: 12.568000 Enter the radius of circle: 1 The area of the circle: 3.142000 The circumference of the circle: 6.284000