Posts

Showing posts with the label c

Compound Interest in c language

Image
C Program To Calculate Compound Interest You need to know : Arithmetic operators. Data type. BODMAS rule.                // To know precedence of an operator. Basic input and output system. Formula Of Compound Interest : Compound Interest = Principle * (1 + Rate / 100 )^T or ci  =  p * pow ( ( 1 + r / 100 ) , t ) Wondering what is pow!!   We got it covered, click here . Tips To Do The Program : Take input of principle amount from user. store in a variable like principle. Do same from Time and Rate. Store it in some appropriate variables like time and rate. Now calculate the Compound Interest using the above formula and store it in a variable say ci. Lastly, show the value of ci to the user. Don't forget to optimize the program for a good look and output. Code : #include<stdio.h> #include<math.h> void main() {       ...

C Program | Count Small Capital Letter Digits Speical Character of an email id

Image
Write a Code on C Program Count Character of an email id : Code: #include<stdio.h> #include<string.h> void main() { int l,i,small,capital,digit,special; char s[100];  printf("Enter an email id:\n"); gets(s);  l=strlen(s); small=0,capital=0,digit=0,special=0; for(i=0;i<l;i++) {   if(s[i]>='a' && s[i]<='z') small++; else if(s[i]>='A' && s[i]<='Z') capital++; else if(s[i]>='0' && s[i]<='9') digit++; else special++; } printf("In string small= %d , capital= %d , digit=%d , special= %d\n",small,capital,digit,special); } Output:  ------------------  String:  Count Vowels , reverse a string , convert lower case to upper

C Program | Count Vowels in a String

Image
Write a Code On C Program , Count Vowels in a String , User Define: Code: #include<stdio.h> #include<string.h> void main() { int i,c=0,l; char s[20]; printf("Enter the string:\n"); gets(s); l=strlen(s); for(i=0;i<l;i++) { if(s[i]=='a' || s[i]=='e' || s[i]=='i'||s[i]=='o' || s[i]=='u' || s[i]=='A' || s[i]=='E'|| s[i]=='I' || s[i]=='O' || s[i]=='U') c++; } printf("The Vowels in string is: %d\n",c); } Output:  -------------------------- C Program: Convert  lower case to upper case

C Program | Convert lower case to upper case

Image
Write a Code for C Program to Convert  lower case to upper case:  Code: #include<stdio.h> #include<string.h> void main() { int i; char s[100]; printf("Enter a string:\n"); gets(s); for(i=0;s[i];i++) { if(s[i]>='a' && s[i]<='z')   s[i]=s[i]-32; } printf("%s\n",s); } Output:

C Program | Reverse a String

Image
Write a Code to Reverse a String | C Program :   Code: #include<stdio.h> #include<string.h> void main() { int i,l; char s[100],k; printf("Enter a string:\n"); gets(s); l=strlen(s); i=0; for(i=0;i<l/2;i++) { k=s[i]; s[i]=s[l-1-i]; s[l-1-i]=k; } printf("%s \n",s); } Output: --------------------------------- C Program: Palindrome in number

C Program | Bubble sort User Define :

Image
Write a C Program to Sort an array using Bubble sort , User Define Array : Code: #include<stdio.h> void main() { int a[20]; int n,i,j,k; printf("Enter the size of array [20]:\n"); scanf("%d",&n); printf("Enter the elements:\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) for(j=0;j<n-1;j++) { if(a[j]>a[j+1]) { k=a[j]; a[j]=a[j+1]; a[j+1]=k; } } for(i=0;i<n;i++) printf("%d\t",a[i]); } Output: ---------------------------------------------------------------------------- Bubble sort : Using Pointer

Find out Max and Min Array | C Program :

Image
Write a C Program to Print Max and Min of an Array : Code: #include<stdio.h> void main() { int max,min,a[20],i,n; printf("Enter size of array [max 20]:\n"); scanf("%d",&n); printf("Enter the elements:\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); max=a[0]; min=a[0]; for(i=0;i<n;i++) { if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } printf("The max= %d and min= %d",max,min); } Output:

Binary Search | C Program :

Image
Write a C Program on Binary Search from user input Elements : Concept of Binary Search: Binary search compares the value assign before to the middle element present of the array. How to perform Binary Search: Whole sorted array divides repeatedly into half by comparing values in array. If the value is less than the item in the middle of the interval,the search will go the interval to the lower half. Otherwise it will do to the upper half of array. Code:  #include<stdio.h> void main() { int a[20],i,se,ln,u,m,l; printf("Enter length of array:\n"); scanf("%d",&ln); printf("Enter the elements of array:\n"); for(i=0;i<ln;i++) { scanf("%d",&a[i]); } printf("Enter the elements to be search:\n"); scanf("%d",&se); l=0; u=ln-1; while(l<=u) { m=(l+u)/2; if(a[m]==se) break; else if(a[m]<se) ...

Find Factorial using Recursion | C Program:

Image
Write a C Program to Find Factorial User given using Recursion :   About factorial: 5! = 5!x4!x3!x2!x1! = 120 Code: #include<stdio.h> void main() { int facto(int); int n,b; printf("Enter a range of factorial:\n"); scanf("%d",&n); b=facto(n); printf("\nThe factorial of %d is %d",n,b); } int facto(int n) { if(n==1) return n; else n=n*facto(n-1); return n; } Output:

Print Fibonacci Series using Recursion | C program :

Image
Write a C Program to Print Fibonacci series user given range using recursion , C program : Code: #include<conio.h> #include<stdio.h> void main() { int fibo(int); int n,i; printf("Enter the range of fibo:\n"); scanf("%d",&n); for(i=0;i<=n;i++) printf("%d\t",fibo(i)); getch(); } int fibo(int i) { if(i==0 || i==1) return 1; else return (fibo(i-1)+ fibo(i-2)); } Output:

Palindrome number | C language

Image
About Palindrome: Write a C-Program to check weather the number is palindrome or not: Code: #include<stdio.h> #include<conio.h> void main() { int n,m,a,b=0; printf("Enter a number:\n"); scanf("%d",&m); n=m; while(n!=0) { a=n%10; n=n/10; b=b*10+a; } printf("%d\n",b); if(b==m) printf("The number is palindrome"); else printf("Not a palindrome"); getch(); } Output:   ------------------- C Program : String Palindrome

Armstrong Number | C-Program

Image
About Armstrong number:   1. Write a C-program to print Armstrong number up to 1000: Code: #include<stdio.h> void main() { int i,j,k,s; printf("The amstrong number are:\n"); for(i=1;i<=1000;i++) { j=i; s=0; while(j!=0) { k=j%10; s=s+k*k*k; j=j/10; } if(s==i) printf("%d\n",i); } } Output: