Skip to content
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

Update Basic_14.c #32

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Basic_1.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// TASK
// Write code to find if the number is even or odd
// Code Below
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
printf("enter the no. to find out whether it is even or odd");
scanf("%d",&a);
if(a%2==0)
{
printf("no. is even");
}
else
{
printf("no. is odd"0);
}
getch();
}
12 changes: 12 additions & 0 deletions Basic_12.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// TASK
// Write code to find cube of a number
// Code Below
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a,b=0,c;
printf("enter the no to take out its cube = ");
scanf("%d",&a);
b=a*a*a;
printf("cube of no. is = %d",b);
getch();
}
30 changes: 30 additions & 0 deletions Basic_14.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// TASK
// Write code to find the average of the elements in an array
// Code Below

#include <stdio.h>

int main()
{
int n, i;
float num[100], sum = 0.0, average;

printf("Enter the numbers of elements: ");
scanf("%d", &n);

while (n > 100 || n <= 0)
{
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}

for(i = 0; i < n; ++i)
{
printf("%d. Enter number: ", i+1);
scanf("%f", &num[i]);
sum += num[i];
}

average = sum / n;
printf("Average = %.2f", average);

return 0;
}