Thursday, 16 May 2013

Calculate number of students having marks more than 60


#include<stdio.h>
#include<conio.h>
void main()
{
int marks[10],i,n=0,m;
clrscr();
printf("CALCULATE NUMBER OF STUDENTS HAVING MARKS >60");

for(i=0;i<=9;i++)
{
printf("\nEnter marks of student number %d",i+1);
scanf("%d",&marks[i]);
}
for(i=0;i<=9;i++)
{
if(marks[i]>60)
{
n++;
}
}
printf("\nNumber of students having marks more than 60 are : %d",n);
getch();
}

Accessing array elements using base address


#include<stdio.h>
#include<conio.h>
void main()
{
int data[5]={1,2,3,4,5};
int i;
int *base_add;
base_add=data;
clrscr();
printf("\t ACCESSING ARRAY ELEMENT USING BASE ADDRESS\N");
printf("\nHere base address is %u",base_add);
for(i=0;i<=4;i++)
{
printf("\nAt address= %u",base_add);
printf("\nWe have data[%d] i.e %d",i,*base_add);
base_add++;
}
getch();
}

Traversing an Array

Traversing an array means to access each and very element of array .It can be accessed using for loops.The data stored in array can be travesred by using for loop and the elements can be accessed by incerement the for loop. The loop starts to traverse array from the start of the array and continue to traverse array until the for lopp continues its execution until the for loop ends.UIn the program below the elements are stored in an array and are travesred using for loop . The loop prints all the elements of array using traversing.
 

Program for traversing an array.

#include<iostream.h>
#include<conio.h>
void main()
{
int data[5]={1,2,3,4,5};
int i;
clrscr();
cout<<""Elements of array Data are";
for(i=0;i<=4;i++)
{
cout<<data[i];
}
getch();
}

 

Find average of two numbers

#include<iostream.h>
#include<conio.h>
void main()
{
float a,b,average;
cout<<"Enter two numbers";
cin>>a>>b;
average=(a+b)/2;
cout<<"\n Average of two numbers is"<<average;
getch();
}

full details in json
Proudly Powered by Blogger.
back to top