Documente Academic
Documente Profesional
Documente Cultură
Your program should count and print:
- the number of hot days (85 or higher),
- the number of pleasant days (60-84), and
- the number of cold days (less than 60).
It should also display the category of each temperature. At the end of the run, display the average
temperature.
#include<stdio.h>
int CalPower(int BaseNumber, int exponent);
int main(void)
{
int x, y, total;
total = CalPower(x,y);
printf("%d exponent %d is %d\n",x,y,total);
return(0);
}
return(result);
}
3. Write a for loop that sums the even values from LIST_SIZE element array list.
for(i=0;i<SIZE;i++) for(i=0;i<SIZE;i++)
if(list[i]%2==0) if((list[i]%2)==0) //if(*(list+i)%2)==0)
sum += list[i]; sum += list[i]; //sum += *(list+i);
return (sum);
printf("The sum of the even numbers }
= %d\n",sum);
}
list
4. Write a program that allows the user to enter number of students and their grade, then it search for a
particular student grade by entering the number of any student and display either the grade of the student
or the student no found.
#include<stdio.h> #include<stdio.h>
#define SIZE 5 #define SIZE 5
#define NOT_FOUND -1
int main(void) int serach(const int no[ ], int target, int n);
{
int ID[SIZE], mark[SIZE],i,key; int main(void)
{
for(i=0; i<SIZE; i++) int ID[SIZE], mark[SIZE], i, key, index;
{
printf("Enter number of student %d > ",i+1); for(i=0; i<SIZE; i++)
scanf("%d",&ID[i]); {
printf("Enter mark for %d > ",ID[i]); printf("Enter number of student %d > ", i+1);
scanf("%d",&mark[i]); scanf("%d",&ID[i]);
} printf("Enter mark for %d > ",ID[i]);
scanf("%d",&mark[i]);
printf("Enter number of student to see his grade "); }
scanf("%d",&key);
printf("Enter number of student to see his grade ");
for(i=0 ; i<SIZE; i++) scanf("%d",&key);
if(ID[i] == key)
{ index = serach(ID, key, SIZE);
printf("The grade for student %d is %d", key, mark[i]);
break; if(index != -1)
} printf("The grade for student %d is %d\n", key, mark[index]);
else
if(i == SIZE) printf("This number %d is not found\n ",key);
printf("This number %d is not found ",key);
return(0);
return (0); }
}
int serach(const int no[ ],int target,int n)
{
int i, found = 0, where;
i=0;
if(found)
where=i;
else
where = NOT_FOUND;
return (where);
}