NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

1.Bitwise Operations(Ask the user to enter two integer numbers. Perform and display the results of bitwise AND, OR, XOR, and NOT operations on the entered numbers.)
#include <stdio.h>

void bitwise_operations(int a, int b) {
printf("AND: %dn", a & b);
printf("OR: %dn", a | b);
printf("XOR: %dn", a ^ b);
printf("NOT a: %dn", ~a);
printf("NOT b: %dn", ~b);
}

int main() {
int a, b;
printf("Enter first integer: ");
scanf("%d", &a);
printf("Enter second integer: ");
scanf("%d", &b);
bitwise_operations(a, b);
return 0;
}

2.Swap Two Numbers Without Using a Temporary Variable(Swap Two Numbers Without Using a Temporary Variable: Use arithmetic operators, bitwise operators, or other techniques. (This is a classic problem where you can use addition and subtraction or XOR operations to swap the values of two variables without using a third temporary variable)

#include <stdio.h>

void swap_numbers(int *a, int *b) {
*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
}

int main() {
int a, b;
printf("Enter first integer: ");
scanf("%d", &a);
printf("Enter second integer: ");
scanf("%d", &b);
swap_numbers(&a, &b);
printf("Swapped numbers: a = %d, b = %dn", a, b);
return 0;
}


3.Convert Fahrenheit to Celsius(Prompt the user to enter a temperature in Fahrenheit. Use arithmetic operators to convert it to Celsius and display the result. Formula)
#include <stdio.h>

void fahrenheit_to_celsius(float fahrenheit) {
float celsius = (fahrenheit - 32) * 5.0 / 9.0;
printf("%.2f Fahrenheit is %.2f Celsiusn", fahrenheit, celsius);
}

int main() {
float fahrenheit;
printf("Enter temperature in Fahrenheit: ");
scanf("%f", &fahrenheit);
fahrenheit_to_celsius(fahrenheit);
return 0;
}

4.Determine if a Number is Even or Odd Using Bitwise AND(Use the bitwise AND operator to determine if a given number is even or odd. Hint: Observe the least significant bit.)
#include <stdio.h>

void is_even_or_odd(int n) {
if (n & 1)
printf("%d is oddn", n);
else
printf("%d is evenn", n);
}

int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);
is_even_or_odd(n);
return 0;
}

5.Determine if a Year is a Leap Year(Use logical operators to determine if a given year is a leap year. A year is a leap year if it is divisible by 4 but not by 100, or if it is divisible by 400)
#include <stdio.h>

void is_leap_year(int year) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
printf("%d is a leap yearn", year);
else
printf("%d is not a leap yearn", year);
}

int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
is_leap_year(year);
return 0;
}
6.Left Shift and Right Shift an Integer(Take an integer input from the user. Left shift and right shift the number by one position and display the results.)
#include <stdio.h>

void shift_operations(int n) {
int left_shift = n << 1;
int right_shift = n >> 1;
printf("Left shift of %d: %dn", n, left_shift);
printf("Right shift of %d: %dn", n, right_shift);
}

int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);
shift_operations(n);
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.