0% found this document useful (0 votes)
18 views6 pages

Merged Assignmentarray

The document contains C code snippets for performing various array operations: 1) Reading integers into an array, calculating the sum and average, and printing the results. 2) Reading integers into an array, counting odd and even numbers, and printing the counts. 3) Reading characters into an array, toggling case, counting vowels and consonants. 4) Reading integers into an array, finding the greatest, second greatest, and smallest numbers. 5) Reading integers into an array, reversing the order, and printing the reversed array. 6) Reading integers into an array, calculating separate sums for odd and even numbers, and printing the sums.

Uploaded by

jhyasshi
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)
18 views6 pages

Merged Assignmentarray

The document contains C code snippets for performing various array operations: 1) Reading integers into an array, calculating the sum and average, and printing the results. 2) Reading integers into an array, counting odd and even numbers, and printing the counts. 3) Reading characters into an array, toggling case, counting vowels and consonants. 4) Reading integers into an array, finding the greatest, second greatest, and smallest numbers. 5) Reading integers into an array, reversing the order, and printing the reversed array. 6) Reading integers into an array, calculating separate sums for odd and even numbers, and printing the sums.

Uploaded by

jhyasshi
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/ 6

//Wap to read 10 integer in an array and do the following: // a.

Find the sum


and average of all the numbers in an array.
#include<stdio.h> int main() { int arr[10]; int i,sum=0; float avg=0;
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++) { sum+=arr[i]; avg=sum/10; } printf(”The sum is %d”,sum);
printf(”The average is %.2f”,avg); }

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);
}

You might also like