Skip to content

Update exercise3.c #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WongChinWee
Copy link

//documentation section
/* Exercise 6 */

//pre-processor section
#include<stdio.h>

//global variable section

//main function section
int main(){
//write here your program
int n,a,i,count=0;
printf("Enter the number of elements in the array:\n");
scanf("%d",&n);
int array[n];
printf("Enter the numbers in the array:\n");
for(i=0;i<n;i++)
scanf("%d",&array[i]);
printf("Enter the number to be searched: ");
scanf("%d",&a);

for(i=0;i<n;i++)
{
    if(array[i]==a)
    {
        printf("Element with value %d is present in arr[]\n",a,i+1);
        count++;
    }
}
if(count==0)
printf("Element with value %d is not present in arr[]\n",a);
else
printf("Element with value %d is present %d times in array[]",a,count);
return 0;

}

//user-defined section

@WongChinWee
Copy link
Author

//documentation section
/* Exercise 6 */

//pre-processor section
#include<stdio.h>

//global variable section

//main function section
int main(){
//write here your program
int n,a,i,count=0;
printf("Enter the number of elements in the array:\n");
scanf("%d",&n);
int array[n];
printf("Enter the numbers in the array:\n");
for(i=0;i<n;i++)
scanf("%d",&array[i]);
printf("Enter the number to be searched: ");
scanf("%d",&a);

for(i=0;i<n;i++)
{
    if(array[i]==a)
    {
        printf("Element with value %d is present in arr[]\n",a,i+1);
        count++;
    }
}
if(count==0)
printf("Element with value %d is not present in arr[]\n",a);
else
printf("Element with value %d is present %d times in array[]",a,count);
return 0;

}

//user-defined section

1 similar comment
@WongChinWee
Copy link
Author

//documentation section
/* Exercise 6 */

//pre-processor section
#include<stdio.h>

//global variable section

//main function section
int main(){
//write here your program
int n,a,i,count=0;
printf("Enter the number of elements in the array:\n");
scanf("%d",&n);
int array[n];
printf("Enter the numbers in the array:\n");
for(i=0;i<n;i++)
scanf("%d",&array[i]);
printf("Enter the number to be searched: ");
scanf("%d",&a);

for(i=0;i<n;i++)
{
    if(array[i]==a)
    {
        printf("Element with value %d is present in arr[]\n",a,i+1);
        count++;
    }
}
if(count==0)
printf("Element with value %d is not present in arr[]\n",a);
else
printf("Element with value %d is present %d times in array[]",a,count);
return 0;

}

//user-defined section

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant