#include <stdio.h> int main() { int n , rem , i = 1 , bn = 0 ; printf("Enter a positive decimal number : "); scanf("%d" , &n); printf("The binary number of decimal %d is : " , n); while (n > 0) { rem = n % 2 ; bn += (i * rem); i = i * 10 ; n = n / 2; } printf("%d\n",bn); return 0 ; }
Sem 1 B.Tech PPS Lab Programmes
*Just some basic programmes , suggest me something to improve.
Subscribe for more such posts..
Dear Reader...
I hope u are like my posts. If so then please don't forget to like , share and follow my blog for more such posts ,also feel free to write suggestions in the comment box given over here.
Thank you...
I hope u are like my posts. If so then please don't forget to like , share and follow my blog for more such posts ,also feel free to write suggestions in the comment box given over here.
Thank you...
Search This Blog
C program to convert a Decimal number to Binary number.
C program to find the GCD of two numbers using Recursion.
#include <stdio.h>
int GCD(int a , int b) { if (b != 0) { return GCD(b , a%b ); } else { return a ; } } int main () { int n1 , n2 ; printf("Enter two integer values : "); scanf("%d %d" , &n1 , &n2); printf("The gcd of two numbers %d and %d = %d\n" , n1 , n2 , GCD(n1, n2)); return 0 ; }
C program to find the sum of digits of a 5 digit number using recursion.
#include <stdio.h> int fun(int n) { int i = n % 10 ; if (n!=0) return i + fun(n/10); else return 0 ; } int main() { int num; printf("Enter any number to find sum of digits: "); scanf("%d" , &num); printf("Sum of digits of %d = %d" , num , fun(num)); return 0 ;
}
C program to find the Factorial of a given number using Recursion.
#include <stdio.h>
int fact(int n ) { if(n >= 1) return n * fact(n - 1); else return 1 ; } int main() { int num; printf("Enter an integer : "); scanf("%d" , &num); printf("Factorial of %d is : %d\n" , num , fact(num)); return 0 ; }
C program to find the sum of the fibonacci series using function.
#include <stdio.h>
long double func (int r) { long double first = -1 , second = 1 , sum = 0 , third; for (int i = 0 ; i < r ; i ++) { third = first + second ; sum = sum + third ; first = second; second = third ; } return sum ; } int main() { int range ; printf("Enter the range: "); scanf("%d" , &range); printf("Sum of Fibonacci series for given range is: %.0Lf\n" , func(range)); return 0 ; }
C program to find the Factorial of a given number using Functions.
#include <stdio.h>
int fact(int n) { int facto = 1 ; for ( int i = n ; i > 0 ; i--) { facto = facto * i ; } return facto ; } int main () { int num ; printf("Enter a number : "); scanf("%d" , &num); printf("Factorial of a given number %d = %d\n" , num , fact(num) ); return 0 ; }
Programme in C using Function that returns the sum of all the odd digits.
#include <stdio.h>int sneha(int n){ int sum = 0 ; while(n != 0) { int rem = n % 10 ; if(rem % 2 != 0) { sum = sum + rem ; } n = n / 10 ; } return sum ; } int main() { int num ; printf("Enter any positive number: "); scanf("%d" , &num); printf("All odd digits sum is: %d\n" , sneha(num)); }
Subscribe to:
Posts (Atom)