Posts

How to check duplicate number in arrays in C language

here's the code in C language #include<stdio.h> int main() {     int array[6]={1,2,5,3,4};     int a,b;     for(a=0;a<5;a++)     {         b=1;         while(array[a]==array[a+b])         {             b++;             break;         }         if(b>1)break;     }     if(b==1)printf("no duplicate number in that array");     else if(b>1)printf("have duplicate number in that array");     return 0; } that is all from me  thank you

Sum Of Digit in C language

itterative version : #include<stdio.h> int main() {     int num,temp,sum;     scanf("%d",&num);     printf("Sum of %d is ",num);     sum=0;     while(num>0)     {         temp=num%10;         sum+=temp;         num/=10;     }     printf("%d",sum);     return 0; } or you can make it recursive #include<stdio.h> int sumofdigit(int num) {     if(num<10)return num;     else return (num%10)+sumofdigit(num/10); } int main() {     int num;     scanf("%d",&num);     printf("Sum of %d is ",num);     while(num>=10)     {         num=sumofdigit(num);     }     printf("%d",num);     return 0; } that is all from me...

bubble sort in C language

Bubble sort is  Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. i f you want to sort it from the smallest to the biggest #include<stdio.h> int main() {     int a,b,temp;     int array[12]={55,17,87,94,78,88,60,93,29,68,51};\     for(a=0;a<11;a++)     {         for(b=0;b<11-a;b++)         {             if(array[b]>array[b+1])             {                 temp=array[b];                 array[b]=array[b+1];                 array[b+1]=temp;             }         }     }     for(a=1;a<12;a++)     {         prin...

Reverse a string in C language

how to reverse a string in C language ? this is the code #include<stdio.h> int main() {     int a,A;     char array[101],temp;     scanf("%s",&array);     a=0;     while(a>=0)     {         if(array[a]=='\0')break;         a++;     }     for(A=0;A<=a/2;A++)     {         temp=array[A];         array[A]=array[a-A-1];         array[a-A-1]=temp;     }     for(A=0;A<a;A++)     {        printf("%c",array[A]);     }     return 0; } or you can simply using function in strrev in string.h #include<stdio.h> #include<string.h>     int main() {     char array[101] ; scanf("%s",&array);   ...

Fibonnaci Number in C language

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. if you want to search the x-th fibonacci digit you can use this code  #include<stdio.h> int main() {     int fib,a,b,c,f;     scanf("%d",&fib);     a=0;     b=1;     c=0;     for(f=1;f<fib;f++)     {         c=a+b;         a=b;         b=c;     }     printf("the fibonacci %dth digit is %d",fib,c);     return 0; } or you want print the all the list of fibonacci number #include<stdio.h> int main() {     int fib,a,b,c,f;     scanf("%d",&fib);     a=0;     b=1;     c=0;     printf("%d digit of fibonnaci\n",fib);     printf("%d %d",a,b);   ...

How to swap number beetwen two number in C language

now how we swap beetwen 2 number ? now we will code it in C language #include<stdio.h> int main() {     int num1,num2,temp;     scanf("%d %d",&num1,&num2);     printf("before swap num1=%d num2=%d\n",num1,num2);     temp=num1;     num1=num2;     num2=temp;     printf("after swap num1=%d num2=%d",num1,num2);     return 0; } or you want swap it without temporary variable ? this is it #include<stdio.h> int main() {     int num1,num2;     scanf("%d %d",&num1,&num2);     printf("before swap num1=%d num2=%d\n",num1,num2);     num1=num1+num2;     num2=num1-num2;     num1=num1-num2;     printf("after swap num1=%d num2=%d",num1,num2);     return 0; } that is all from me thanks you

how to find the largest number or smallest number in C language

array of number : 17 87 94 78 88 60 93 29 68 51 code to find the greatest number #include<stdio.h> int main() {     int array[11]={17,87,94,78,88,60,93,29,68,51};     int a,max;     max=0;//set max to 0 or -99999 so we can search the greatest number     for(a=0;a<11;a++)//why a<11 because I have an array that can load up to 10 numbers     {         if(array[a]>=max)//if array[a] is greater than max then we replace max with array[a]         {             max=array[a];         }     }     printf("The Greatest number in that array is %d",max);     return 0; } that all from me  thank you

Prime Number in C language

Prime Number is  a whole number greater than 1 whose only factors are 1 and itself. A factor is a whole numbers that can be divided evenly into another number. the example of prime number is 2,3,5,7,11,13,17,19 and so on. now we will make a code in C to determine is it prime number or not #include<stdio.h> int main() {    int num,n,check;    scanf("%d",&num);    check=0;    for(n=1;n<=num;n++)    {       if(num%n==0)check++;    }    if(check==2)printf("%d is Prime Number",num);    else printf("%d is Not Prime Number",num);    return 0; } in some competitive coding you will get time limit if you use this code many ways to make this coding That is all from me thank you 

Factorial in C language

Factorial is the natural number n is the product of multiplication between positive integers less than or equal to n. Factorial is written with the symbol "!" Example: 4! = 4 x 3 x 2 x 1                3! = 3 x 2 x 1 Now we will make it in code first in the itterative form #include <stdio.h> // for standard input output int main () {    int factorial,f jml;    scanf ("% d", & factorial);    jml = 1;    if (factorial == 1) printf ("% d", factorial);    for (f = 1; f <= factorial; f ++)       {            jml = jml * f;        }    printf ("% d \ n", jml);    return 0; } next we will make it recursive #including <stdio.h> int fact (int factorial) {    if (factorial == 1) return factorial;    else returns factorial * fact (factorial - 1); } ...

odd or even in C language

Image
 That is all from me thank you