Posts

Showing posts from September, 2017

My Subject Blog

C Program for Pyramid and Pattern

/* Pattern Programs:(WAP to print pattern like below) *   *  *   *  *  *   *  *  *  *  */ #include <stdio.h> int main(void) { int i,j,n; printf("Enter How Many Rows You Want :"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<=i;j++) { printf("* "); } printf("\n"); } return 0; } /* Pattern Programs:(WAP to print pattern like below) 1  2 2  3 3 3  4 4 4 4 */ #include <stdio.h> int main(void) { int i,j,n; printf("Enter How Many Rows You Want :"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<=i;j++) { printf("%d ",i+1); } printf("\n"); } return 0; } /* Pattern Programs:(WAP to print pattern like below) 1   0 1   1 0 1   0 1 0 1 */ #include <stdio.h> int main(void) { int i,j,n; printf("Enter How Many Rows You Want :"); scanf("%d",&n); for(...

C Program Palindrome

/*  Write a program to find whether a number is palindrome or not.  */ #include <stdio.h> int main(void) { int no,sum=0,temp; printf("Enter Number : "); scanf("%d",&no); temp=no; while(no>0) { sum = (sum * 10)+(no % 10); no = no / 10; } if(temp == sum) { printf("\n %d is Palindrome",temp); } else { printf("\n %d is not Palindrome",temp); } return 0; }

C Program Calculator

/*   Write a program to make a simple calculator using switch..case statement.   */ #include <stdio.h> int main(void) { int a=10,b=20,ch; do { printf("\n================"); printf("\nSelect Operation"); printf("\n================"); printf("\n1 - Addition"); printf("\n2 - Substraction"); printf("\n3 - Multiplication"); printf("\n4 - Division"); printf("\n5 - Modulo"); printf("\n6 - Exit"); printf("\n================"); printf("\nEnter Your Choice :"); scanf("%d",&ch); printf("Enter First Value :"); scanf("%d",&a); printf("Enter Second Value :"); scanf("%d",&b); switch(ch) { case 1: printf("\nAnswer = %d",a+b); break; case 2: printf("\nAnswer = %d",a-b); break; case 3: printf("\nAnswer = %d",a*b); break; case 4: ...

C Program Find Minimum Value

/* Write a program to find minimum no out of three numbers by using Conditional Operator(nested..if ).  */ #include <stdio.h> int main(void) { int a,b,c; printf("Enter Three Values : "); scanf("%d %d %d",&a,&b,&c); printf("\n Minimum Value is : %d",((a<b)?(a<c?a:c):(b<c?b:c))); return 0; }

C Program Odd or Even

/*  Write a program to find out whether a number is odd / even by using different if..else statements.   */ #include <stdio.h> int main(void) { int n; printf(" Enter any Number :"); scanf("%d",&n); if(n%2==0) { printf("\n %d is Even",n); } else { printf("\n %d is Odd",n); } if(n&1==1) { printf("\n %d is Odd",n); } else { printf("\n %d is Even",n); } return 0; }

C Program Armstrong number

/* Write a program to print Armstrong number ( or Narcissistic no) between 0 to 999.( Armstrong no= addition of cube of every digit of a no, e.g. 153 is Armstrong due to 13+53+33=153)   */ #include <stdio.h> int main(void) { int n,r,no=0,sum=0; while(no<1000) { n=no; sum = 0; while(n>0) { r = n % 10; sum = sum + (r * r *r); n = n / 10; } if(sum==no) { printf("%d ",no); } no++; } return 0; }

C Program Prime Number

/*  Write a program to print first N prime numbers. ( no factor other than 1 & itself)   */ #include <stdio.h> int main(void) { int n,i,no=2; printf("How many Prime Number You Want : "); scanf("%d",&n); while(n>0) { i=2; while(i<no) { if(no%i==0) { break; } i++; } if(no==i) { printf(" %d",i); n--; } no++; } return 0; }

C Program Reverse the Digits

/*  Write a program to reverse sequence of digit.  */ #include <stdio.h> int main(void) { int n,r,sum=0; printf("Enter Any Number : "); scanf("%d",&n); while(n>0) { r = n % 10; sum = (sum * 10)+r; n = n / 10; } printf(" Reverse = %d",sum); return 0; }

C Program Inverse Series

/* Write a program to print 1+1/2+1/3+1/4+………+1/N series.   */ #include <stdio.h> int main(void) { int n; float sum=0; printf("Enter Value of N : "); scanf("%d",&n); while(n>0) { sum = sum + (1.0/n); n--; } printf(" Sum = %.2f",sum); return 0; }

C Program Fibonacci Series

/*  Write a Program to print Fibonacci series.(1 1 2 3 5 8 13……)   */ #include <stdio.h> int main(void) { int a=1,b=1,n; printf("How Many Fibonacci No of you want to print : "); scanf("%d",&n); printf("\n %d %d ",a,b); while(n>0) { printf("%d ",a+b); b=a+b; a=b-a; n--; } return 0; }

C Program Odd Number Series

/* Write a program for following Series:  1 + 3 + 5 +… + n    */ #include <stdio.h> int main(void) { int n; printf("Enter Value of n :"); scanf("%d",&n); printf(" Total Sum = %d",(n*n)); return 0; }

C Program Cube Series

/* Write a program for following Series: 1^3 + 2^3 + 3^3 + 4^3 … + n^3   */ #include <stdio.h> int main(void) { int n; printf("Enter Value of n :"); scanf("%d",&n); printf(" Total Sum = %d",((n*(n+1))/2)*((n*(n+1))/2)); return 0; }

C Program Solving Quadratic Equation

/* Write a program to solve Quadratic Equation.   */ #include <stdio.h> int main(void) { int a,b,c,delta; float x1,x2; printf("Enter Co-efficient of X2 : "); scanf("%d",&a); printf("Enter Co-efficient of X : "); scanf("%d",&b); printf("Enter Constant : "); scanf("%d",&c); delta = (b *b)-(4*a*c); x1 = (-b + sqrt(delta))/(2*a); x2 = (-b - sqrt(delta))/(2*a); printf("\n First Root = %.2f \n Second Root = %.2f",x1,x2); return 0; }

C Program Interest Calculation

/* Write a Program to find out simple interest.  I=(P*R*N)/100    */ #include <stdio.h> int main(void) { int N; float P, R, I; printf("Enter Amount P :"); scanf("%f",&P); printf("Enter Rate R :"); scanf("%f",&R); printf("Enter No of Years N :"); scanf("%d",&N); I = (P*R*N)/100; printf("\n Interest = %.2f",I); return 0; }

C Program Celsius to Fahrenheit

/* Write a Program to convert the Celsius to Fahrenheit. F=(C*1.8)+32  */ #include <stdio.h> int main(void) { float F,C; printf("Enter Temprature in Celsius " ); scanf("%f",&C); F = (C * 1.8) + 32; printf("\n %.2f Celsius = %.2f Fahrenheit",C, F); return 0; }

C Program Swap Values

/* Write a program to swap (interchange) values of two variables with and without using third variable.  */ #include <stdio.h> int main(void) { int a,b,c; printf("Enter Value of a :"); scanf("%d",&a); printf("Enter Value of b :"); scanf("%d",&b); printf("\nBefore Swapping a = %d b = %d",a,b); c=a; a=b; b=c; printf("\nAfter Swapping (Using 3rd Variable) a = %d b = %d",a,b); a=a+b; b=a-b; a=a-b; printf("\nAfter Swapping (Without 3rd Variable) a = %d b = %d",a,b); return 0; }

C Program Conversion of Distance

/* The distance between two cities (In KM) is input through keyboard. Write a program to convert and print this distance in meters, feet, inches & centimeters.  */ #include <stdio.h> int main(void) { float km; printf("Enter Length in KiloMeter : "); scanf("%f",&km); printf("\n %.2f KM = %.2f Meters",km,km*1000); printf("\n %.2f KM = %.2f Feets",km,km*3280.84); printf("\n %.2f KM = %.2f Inches",km,km*39370.08); printf("\n %.2f KM = %.2f Centimeters",km,km*1000*100); return 0; }

C Program Day Month Calculation

/* Write a program to convert days into months and days.  */ #include <stdio.h> int main(void) { int days; printf("Enter No of Days : "); scanf("%d",&days); printf("\n Month = %d and Days = %d",days/30,days%30); return 0; }

C Program Mathematical Operations

/*Write a program that reads two nos. from keyboard and gives their addition, subtraction, multiplication, division and modulo.  */ #include <stdio.h> int main(void) { int i,j; printf("Enter First Value : "); scanf("%d",&i); printf("Enter Second Value : "); scanf("%d",&j); printf("\nAddition = %d",i+j); printf("\nSubtraction = %d",i-j); printf("\nMultiplication = %d",i*j); printf("\nDivision = %d",i/j); printf("\nModulo = %d",i%j); return 0; }

C Program Character to ASCII

/* Write a Program to which accepts a character from keyboard & display its ASCII code. */ #include <stdio.h> int main(void) { char ch; printf("Enter any character : "); scanf("%c",&ch); printf("ASCII of %c is %d",ch,ch); return 0; }

C Program Hello World

/*Write a Program to display “Hello World” on the screen.*/ #include <stdio.h> int main(void) { printf("Hello World"); return 0; }

Followers