Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Monday, September 12, 2011

Example of Array

Q. Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test.

Ans.
/*We assume that maximum marks in internal test is 500. */
#include<stdio.h>
#include<conio.h>
#define SIZE 5
int main()
{
 int arr[SIZE];
 int i,j,max=0,min=0;
 for(i=1; i<=SIZE; i++)
 {
   printf("Enter %d student marks : ",i);
   scanf("%d",&arr[i]);
 }
 for(i=1; i<=SIZE; i++)
 {
  if(arr[i]/5 > 50)
  {
    max++;
    printf("\nMarks which scored more than 50%% is %d",arr[i]);
  }
  else
  {
    min++;
    printf("\nMarks which scored less than 50%% is %d",arr[i]);
  }
 } 
 printf("\n");
 printf("\nTotal number of students who scored more  than 50%% = %d",max);
 printf("\nTotal number of students who scored less than 50%% = %d",min);
 getch();
 return 0;
}


      Output of the above program :
Enter 1 student marks : 450
Enter 2 student marks : 152
Enter 3 student marks : 266
Enter 4 student marks : 65
Enter 5 student marks : 123

Marks which scored more than 50% is 450
Marks which scored less than 50% is 152
Marks which scored more than 50% is 266
Marks which scored less than 50% is 65
Marks which scored less than 50% is 123

Total number of students who scored more than 50% =  2 
Total number of students who scored less than 50% =  3 

Sunday, September 4, 2011

Data type in C

Data Type In C Language

There are mainly three data type in C as following :
  1. Basic Data Type
    • int
    • char
    • float
    • long
    • double
    • long double
  2. Derived Data Type
    • Array
    • Pointer
    • function
  3. User Define Data Type
    • structure
    • union
    • enumerated
    • typedef

Following table tell which data type how much allocate memory?

Data Type Memory Allocation
int 2 byte
long 4 byte
float 4 byte
double 8 byte
long double 10 byte
char 1 byte

In data types we also learn about link list,file handling and more. So now we are entering in real c world i.e. C programming.