0% found this document useful (0 votes)
3 views

ass

The document contains multiple C programs demonstrating various functionalities such as searching for an element in an array, sorting an array in ascending and descending order, counting alphabetic characters in a string, and counting positive and negative integers in an array. Each program includes a main function and a specific function to perform the required task. However, there are some issues in the code, such as incorrect loop conditions and missing variable initializations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ass

The document contains multiple C programs demonstrating various functionalities such as searching for an element in an array, sorting an array in ascending and descending order, counting alphabetic characters in a string, and counting positive and negative integers in an array. Each program includes a main function and a specific function to perform the required task. However, there are some issues in the code, such as incorrect loop conditions and missing variable initializations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

//WAP to search an elements of an array usinf function

/*#include<stdio.h>
void search(int a[], int size, int ele);
int main(){
int a[100],i,size,element;
printf("Enter the size of the array:");
scanf("%d",&size);

for(i=0; i<=size ;i++)


{
printf("Enter the number:");
scanf("%d",&a[i]);
}
printf("Enter the element for searching:");
scanf("%d",&element);
search(a,size,element);
return 0;
}
void search(int a[], int size, int ele){
int found=0,i;
for(i=0;i<=size;i++){
if(a[i]==ele){
found=1;
break;
}
}
if (found){
printf("The elemnt has successfully foun in the array");
}
else{
printf("The element hasnot been found ");
}

}*/
//WAP to sort an array using ascending using a function
/*#include<stdio.h>
void sort(int a[], int size);
int main(){
int a[100],i,size,element;
printf("Enter the size of the array:");
scanf("%d",&size);

for(i=0; i<size ;i++)


{
printf("Enter the number:");
scanf("%d",&a[i]);
}
printf("Element before shorting:\n");
for(i=0;i<size;i++){
printf("%d\t",a[i]);
}
sort(a,size);

return 0;
}
void sort(int a[], int size){
int i,j,temp;
for(i=0;i<size;i++){
for(j=i+1;j<size;j++){
if(a[i]>a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nArray after sorting\n");
for(i=0;i<size;i++){
printf("%d\t",a[i]);
}
}*/
//WAP to sort an array using descending using a function
/*#include<stdio.h>
void sort(int a[], int size);
int main(){
int a[100],i,size,element;
printf("Enter the size of the array:");
scanf("%d",&size);

for(i=0; i<size ;i++)


{
printf("Enter the number:");
scanf("%d",&a[i]);
}
printf("Element before shorting:\n");
for(i=0;i<size;i++){
printf("%d\t",a[i]);
}
sort(a,size);

return 0;
}
void sort(int a[], int size){
int i,j,temp;
for(i=0;i<size;i++){
for(j=i+1;j<size;j++){
if(a[i]<a[j]){
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\nArray after sorting\n");
for(i=0;i<size;i++){
printf("%d\t",a[i]);
}
}
//WAP to calculate alpha character from a string using a fucntion
#include<stdio.h>
int char_count(char a[]);
int main(){
char a[100];
printf("Enter nay string:");
scanf("%[^\n]",a);
int c=char_count(a);
printf("The total number of character is:%d",c);
return 0;
}
int char_count(char a[]){
int count=0,i;
for(i=0;a[i]!='\0';i++){
if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z') ){
count++;
}
}
return count;
}
*/
#include<stdio.h>
int int_count(int a[]);
int main(){
int a[100],size,i;
printf("Enter the size:");
scanf("%d",size);
for(i=0;i<size;i++){
printf("Enter the element %d",i+1);
scanf("%d",&a[i]);
}

return 0;
}
int int_count(int a[]){
int count=0,i,ng=0,size;
for(i=0;i<size;i++){
if(a[i]>=0){
count++;
}
else{
ng++;
}
}
printf("The toal positive number is %d",count);
printf("The toal negative number is %d",ng);
}

You might also like