0% found this document useful (0 votes)
6 views12 pages

Assignment 1-3

The document contains a series of C programming exercises that prompt the user for input and perform various arithmetic operations or manipulations on the input numbers. Each question includes code snippets that demonstrate how to add, subtract, multiply, divide, and extract digits from one, two, or three-digit numbers. The exercises also include reversing digits and calculating sums of digits for two and three-digit numbers.

Uploaded by

ithikashr97516
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views12 pages

Assignment 1-3

The document contains a series of C programming exercises that prompt the user for input and perform various arithmetic operations or manipulations on the input numbers. Each question includes code snippets that demonstrate how to add, subtract, multiply, divide, and extract digits from one, two, or three-digit numbers. The exercises also include reversing digits and calculating sums of digits for two and three-digit numbers.

Uploaded by

ithikashr97516
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Question1:

Get a number from user and add 2 to that number and print the result.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number;

printf("Enter a number: ");

scanf("%d", &number);

number += 2;

printf("Result: %d\n", number);

return 0;

Output:

Question2:
Get a number from user and subtract 5 to that number and print the result.

Code:

//2022510023-ITHIKASH R

#include<stdio.h>

int main() {

int number;

printf("Enter a number: ");

scanf("%d", &number);

number -= 5;

printf("Result: %d\n", number);


return 0;

Output:

Question3:
Get a number from user and multiply 3 to that number and print the result.

Code:

//2022510023-ITHIKASH R

#include<stdio.h>

int main() {

int number;

printf("Enter a number: ");

scanf("%d", &number);

number *= 3;

printf("Result: %d\n", number);

return 0;

Output:
Question4:
Get a number from user and divide by the number by 6 and print the Quotient.

Code:

//2022510023-ITHIKASH R

#include<stdio.h>

int main() {

int number;

printf("Enter a number: ");

scanf("%d", &number);

number /= 6;

printf("Result: %d\n", number);

return 0;

Output:

Question5:
Get a number from user and divide by the number by 8 and print the remainder.

Code:

//2022510023-ITHIKASH R

#include<stdio.h>

int main() {

int number;

printf("Enter a number: ");

scanf("%d", &number);

number %= 8;

printf("Result: %d\n", number);


return 0;

Output:

Question6:
Get a two-digit number from user and print the one’s digit.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number;

printf("Enter a two-digit number: ");

scanf("%d", &number);

int ones_digit = number % 10;

printf("One's digit: %d\n", ones_digit);

return 0;

Output:
Question7:
Get a two-digit number from user and print the ten’s digit.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number;

printf("Enter a two-digit number: ");

scanf("%d", &number);

int tens_digit = number / 10;

printf("Ten's digit: %d\n", tens_digit);

return 0;

Output:

Question8:
Get a three-digit number from user and print the one’s digit.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number;

printf("Enter a three-digit number: ");


scanf("%d", &number);

int ones_digit = number %10;

printf("one's digit: %d\n", ones_digit);

return 0;

Output:

Question9:
Get a three-digit number from user and print the hundred’s digit.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number;

printf("Enter a three-digit number: ");

scanf("%d", &number);

int hundreds_digit = number / 100;

printf("hundred's digit: %d\n", hundreds_digit);

return 0;

}
Output:

Question10:
Get a three-digit number from user and print the ten’s digit.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number;

printf("Enter a three-digit number: ");

scanf("%d", &number);

int tens_digit = (number / 10) % 10;

printf("Ten's digit: %d\n", tens_digit);

return 0;

Output:
Question11:
Get a two-digit number from the user and print sum of the digits.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number, tens_digit, ones_digit, sum;

printf("Enter a two-digit number: ");

scanf("%d", &number);

tens_digit = number / 10;

ones_digit = number % 10;

sum = tens_digit + ones_digit;

printf("Sum of the digits: %d\n", sum);

return 0;

Output:
Question12:
Get a three-digit number from user and print sum the digits.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number, hundreds_digit, tens_digit, ones_digit, sum;

printf("Enter a three-digit number: ");

scanf("%d", &number);

hundreds_digit = number / 100;

tens_digit = (number / 10) % 10;

ones_digit = number % 10;

sum = hundreds_digit + tens_digit + ones_digit;

printf("Sum of the digits: %d\n", sum);

return 0;

Output:
Question13:
Get a two-digit number from user and print the reverse of the number.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number, ones_digit, tens_digit, reversed_number;

printf("Enter a two-digit number: ");

scanf("%d", &number);

tens_digit = number / 10;

ones_digit = number % 10;

reversed_number = ones_digit * 10 + tens_digit;

printf("Reversed number: %d\n", reversed_number);

return 0;

Output:

Question14:
Get a three-digit number from user and print the reverse of the number.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number, ones_digit, tens_digit, hundreds_digit, reversed_number;

printf("Enter a three-digit number: ");


scanf("%d", &number);

hundreds_digit = number / 100;

tens_digit = (number / 10) % 10;

ones_digit = number % 10;

reversed_number = ones_digit * 100 + tens_digit * 10 + hundreds_digit;

printf("Reversed number: %d\n", reversed_number);

return 0;

Output:

Question15:
Get a four-digit number from user and only reverse thefirst two digits of the number, then print the number.

Code:

//2022510023-ITHIKASH R

#include <stdio.h>

int main() {

int number, first_two_digits, reversed_first_two_digits, last_two_digits, reversed_number;

printf("Enter a four-digit number: ");

scanf("%d", &number);

first_two_digits = number / 100;

last_two_digits = number % 100;

reversed_first_two_digits = (first_two_digits % 10) * 10 + (first_two_digits / 10);

reversed_number = reversed_first_two_digits * 100 + last_two_digits;

printf("Reversed number with only the first two digits reversed: %d\n", reversed_number);
return 0;

Output:

You might also like