Merged Assignmentarray
Merged Assignmentarray
1
/*Wap to read 15 integers in an array and count total no of odd and even present
in that array*/
#include<stdio.h> int main() { int arr[15]; int i,odd=0,even=0; int rem;
printf(”Enter the number in the array”); for(i=0;i<15;i++) { scanf(”%d”,&arr[i]);
} for(i=0;i<15;i++) { printf(”%d\t”,arr[i]); }
for(i=0;i<15;i++) { rem=arr[i]%2;
if(rem==0) { even++; } else{ odd++; } } printf(”The odd count is %d”,odd);
printf(”The even count is %d”,even);
}
1
/*. Wap to read 10 character in an array and do the following: a. Toggle the
character and print in console.[if the character in array is in lower case you must
convert to upper case and print and if the character in array is in upper case
you must convert to lower case and print in console] b. Count the total number
of vowel and consonant present in an array.*/
#include<stdio.h> int main() { char arr[10]; int i; char up_alpha,low_alpha;
printf(”Enter the character [a-z or A-Z]\n”);
for(i=0;i<10;i++) { scanf(”%c”,&arr[i]); } for(i=0;i<10;i++) { printf(”%c\n”,arr[i]);
}
for(i=0;i<10;i++) { if(arr[i]>=’A’ && arr[i]<=’Z’){ up_alpha=arr[i]+32;
printf(”%c”,up_alpha); } else if(arr[i]>=’a’ && arr[i]<=’z’){ low_alpha=arr[i]-
32; printf(”%c”,low_alpha); } else{ printf(”Enter the valid character”); } }
}
1
#include <stdio.h>
int main() { int arr[10]; int i, greatest,s_greatest,smallest;
printf(”Enter 10 numbers:\n”);
for (i = 0; i < 10; i++) {
scanf(”%d”, &arr[i]); }
greatest = arr[0]; s_greatest=arr[0]; smallest=arr[0];
for (i = 1; i < 10; i++) { if (arr[i] > greatest) { greatest = arr[i];
} else if(s_greatest<greatest && arr[i]>s_greatest ) { s_greatest=arr[i]; } else
if(arr[i]<smallest){ smallest=arr[i]; }
}
printf(”The largest number is: %d\n”, greatest); printf(”The second largest
number is: %d\n”, s_greatest); printf(”The second smallest number is: %d\n”,
smallest);
return 0; }
1
//Reverse the number present in an array and print in console #include
<stdio.h>
int main() { int arr[10]; int i;
printf(”Enter the numbers\n”); for (i = 0; i < 10; i++) { scanf(”%d”,&arr[i]);
}
for (i = 0; i < 10; i++) { printf(”%d\n”, arr[i]); } printf(”The number in the
reverse order”);
for(i=9;i>=0;i--){ printf(”%d\t”,arr[i]); } return 0; }
1
//Find the sum of even and odd number separately and print in console.
#include<stdio.h> int main() { int arr[15]; int i,oddsum=0,evensum=0; int
rem;
printf(”Enter the number in the array”); for(i=0;i<10;i++) { scanf(”%d”,&arr[i]);
} for(i=0;i<10;i++) { printf(”%d\t”,arr[i]); }
for(i=0;i<10;i++) { rem=arr[i]%2;
if(rem==0) { evensum=arr[i]; } else{ oddsum=arr[i]; } } printf(”The odd sum
is %d”,oddsum); printf(”The even sum is %d”,evensum);
}