Skip to content

Commit

Permalink
added 4.c to class codes
Browse files Browse the repository at this point in the history
Changes to be committed:
	new file:   assignment-3/4-if-even-odd
	modified:   others/classes/2023-04-11/2.c
	modified:   others/classes/2023-04-11/3.c
	new file:   others/classes/2023-04-11/4.c

Changes not staged for commit:
	deleted:    assignment-3/4-if-even-odd
  • Loading branch information
Surajkumarsaw1 committed Apr 11, 2023
1 parent 2b67eb3 commit 97a78e4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
Binary file added assignment-3/4-if-even-odd
Binary file not shown.
16 changes: 15 additions & 1 deletion others/classes/2023-04-11/2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@
int main() {
int arr[20], sodd =0 , seven=0, i;

printf("Enter 20 numbers : ");

// takes 20 input
for ( i = 0; i < 20;i++){
scanf("%d", &arr[i]);
}

// comparision using ternary operator for even or odd
// comparision for even or odd
for ( i = 0; i < 20; i++){
// comparision using ternary operator for even or odd
arr[i]%2 == 0 ? (seven += arr[i]) : (sodd += arr[i]);


// comparision using if else operator for even or odd
// if ( arr[i] == 0){
// // if even
// seven += arr[i];
// }
// else{
// // if odd
// sodd += arr[i];
// }
}

// printing result
Expand Down
12 changes: 11 additions & 1 deletion others/classes/2023-04-11/3.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
int main() {
int arr[20], sum =0, i, temp, count;

printf("Enter 10 numbers : ");

// taking 10 input
for ( i = 0; i < 10;i++){
scanf("%d", &arr[i]);
Expand All @@ -20,8 +22,16 @@ int main() {
temp/=10;
}

// cheching if 2 digit number
// checking if 2 digit number
count == 2 ? (sum += arr[i]) : (sum += 0);

// checking if 2 digit number using if else

// if (count == 2){
// // if 2 digit number
// sum += arr[i];
// }

}
printf("Sum of all two digit numbers : %d", sum);
return 0;
Expand Down
30 changes: 30 additions & 0 deletions others/classes/2023-04-11/4.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// WAP to take input of 10 number, display product of all numbers divisible by 5.
#include <stdio.h>

int main() {

int arr[10], product = 1, i;

printf("Enter 10 numbers : ");

// Taking input of 10 numbers
for (i = 0; i < 10; i++){
scanf("%d",&arr[i]);
}

// product of numbers,which is multiple of 5
for (i = 0; i < 10; i++){
// checking if divisible by 5 using ternary operator
arr[i]%5 == 0 ? (product *= arr[i]) : (product *= 1);

// checking if divisible by 5 using if operator
// if (arr[i]%5 == 0){
// // if divisible by 5
// product *= arr[i];
// }
}

// printing result
printf("Product = %d",product);
return 0;
}

0 comments on commit 97a78e4

Please sign in to comment.