C Assignment
C Assignment
61. Write a C program to convert the given binary number into its
equivalent decimal.
INPUT:
#include <stdio.h>
return decimalNumber;
}
int main() {
int binaryNumber;
return 0;
}
OUTPUT:
45. Write a program to compute the surface area and volume of
a cube.
INPUT:
#include<stdio.h>
main(){
float a;
printf("Enter the side of the cube:");
scanf("%f",&a);
float surfacearea = 6*a*a;
printf("The surfacearea of cube is: %f\n",surfacearea);
float volume = a*a*a;
printf("The volume of cube is: %f ",volume);
}
OUTPUT:
INPUT:
#include<stdio.h>
main(){
int x;
printf("Enter year\n");
scanf("%d",&x);
if(
( (x%4==0)&&(x%100!=0))||(x%400==0)
){
printf("%d is an leap year",x);
}
else{
printf("%d is not an leap year",x); /
}
}
OUTPUT
40. Write the program to generate Fibonacci sequences.
INPUT:
#include<stdio.h>
main(){
int fib1=0,fib2=1,fib3,n,count=0;
printf("Enter the value of n \n");
scanf("%d",&n);
printf("First %d fibonacci numbers are \n",n);
printf("%d\n",fib1);
printf("%d \n",fib2);
count=2;
while(count<n){
fib3 = fib1+fib2;
count++;
printf("%d \n", fib3);
fib1=fib2;
fib2=fib3;
}
}
OUTPUT:
INPUT:
#include<stdio.h>
main(){
int x; //Assuming x = number of days
printf("enter the number of days");
scanf("%d",&x);
int year = x / 365;
int week = ( x % 365)/7;
int days = ( x% 365)%7;
printf("year =%d \n",year);
printf("week = %d\n",week);
printf("days=%d \n",days);
}
OUTPUT:
INPUT:
#include<stdio.h>
main()
{
int x,remainder,reverse=0;
printf("enter any integer\n");
scanf("%d",&x);
while(x!=0){
remainder=x%10;
reverse=( reverse*10 )+ remainder;
x = x/10;
}
printf("Reverse number= %d\n",reverse);
}
OUTPUT:
INPUT:
#include<stdio.h>
main()
{
int AR[50],OAR[50],EAR[50];
int i,j=0,k=0,n;
printf("enter the number of elements:\n");
scanf("%d",&n);
printf("enter the elements of the array:\n");
for(i=0;i<n;i++)
{
scanf("%d",&AR[i]);
}
for(i=0;i<n;i++)
{
if(AR[i]%2==0)
{
EAR[j]=AR[i];
j++;
}
else{
OAR[k]=AR[i];
k++;
}
}
INPUT:
#include<stdio.h>
main()
{
int number;
int operater;
printf("enter an integer");
scanf("%d",&number);
operater=number;
number=number<<2;
printf("%d*4=%d\n",operater,number);
}
OUTPUT:
INPUT:
#include<stdio.h>
main()
{
int a,b;
printf("enter two integers\n");
scanf("%d%d",&a,&b);
printf("\n before swapping a=%d and b=%d",a,b);
a=a^b;
b=a^b;
a=a^b;
printf("\n after swapping a=%ld and b=%ld",a,b);
}
OUTPUT: