World Top Softwares
Login Please

Join the forum, it's quick and easy

World Top Softwares
Login Please
World Top Softwares
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
 
 

Display results as :
 


Rechercher Advanced Search

Log in

I forgot my password

Latest topics
» Practically as cut-price as files
9th program EmptyMon Aug 01, 2011 11:44 pm by Guest

» Netbook Brands
9th program EmptyMon Aug 01, 2011 5:39 am by Guest

» backlinks checker backlink service
9th program EmptySun Jul 31, 2011 8:56 am by Guest

» how to buy facebook fans f4
9th program EmptySat Jul 30, 2011 2:34 pm by Guest

» Alle bijzondere dingen in de zaanstreek
9th program EmptySat Jul 30, 2011 8:11 am by Guest

» HERE YOU CAN POST ALL WEBSITE LINKS...
9th program EmptyWed Aug 26, 2009 2:16 pm by onesimpletech

» cool web site for all must check it
9th program EmptyMon Jul 06, 2009 2:32 pm by Snopy Cobra

» poetry spirit
9th program EmptyMon Jul 06, 2009 2:31 pm by Snopy Cobra

» best to learn VC++
9th program EmptySun May 10, 2009 3:22 pm by Guest

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search
Statistics
We have 30 registered users
The newest registered user is deigavr

Our users have posted a total of 191 messages in 126 subjects
Who is online?
In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest

None

[ View the whole list ]


Most users ever online was 125 on Wed Apr 07, 2021 9:18 am
RSS feeds


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 



9th program

Go down

9th program Empty 9th program

Post by Snopy Cobra Sun Jan 04, 2009 7:42 pm

Objective

Study the way to use Arrays.

Theory

“A capability that enables the user to define a set of ordered data items known as an array.”

An array is a data structure consisting of a group of elements that are accessed by indexing. In most programming languages each element has the same data type and the array occupies a contiguous area of storage. Arrays can be classified as fixed-sized arrays (sometimes known as static arrays) whose size cannot change once their storage has been allocated.

Arrays are useful critters because they can be used in many ways. Arrays are essentially a way to store many values under the same name. You can make an array out of any data-type.

Declaration of an array
Like any other variable arrays must be declared before they are used. The general form of declaration is:

datatype variable-name[10];


Multidimensional arrays

The most useful aspect of arrays is multidimensional arrays. Multidimensional arrays can be described as "arrays of arrays". Multi-dimensional arrays are accessed using more than one index.

This is a graphic of what a two-dimensional array looks like when I visualize it.

For example:

datatype variable-name[10][10];



Task
Write a program that sort an integer array of 5.
coding
#include<stdio.h>
void main(void)
{
int i,j,k,temp;
int arr[5];
{
printf("enter 5 numbers=\n");
scanf("%d",&arr[0]);
scanf("%d",&arr[1]);
scanf("%d",&arr[2]);
scanf("%d",&arr[3]);
scanf("%d",&arr[4]);
for(i=0;i<5;i++)
{
for(j=0;j<4-i;i++)
{
if (arr[j]>arr[j+1])
{
arr[j]=temp;
arr[j]=arr[j+1];
arr[j+1]=temp;
}
for (k=0;k<=4;k++)
{
printf("%d",&arr[k]);
}


2. Write a program that accepts values into two 2x2 arrays. Calculate the sum of the two matrices and store the matrix result in another array. Also display the result on the screen.

#include <stdio.h>
void main (void)
{
int t[2][2],y[2][2],u[2][2];
printf ("ENTER 1st MATRIX");
printf ("\nEnter 1ST ROW\n");
scanf ("%d",&t[0][0]);
scanf ("%d",&t[0][1]);
printf ("\nENTER 2ND ROW\n");
scanf ("%d",&t[1][0]);
scanf ("%d",&t[1][1]);
printf ("\nMATRIX 2\n");
printf ("ENTER FIRST ROW\n");
scanf ("%d",&y[0][0]);
scanf ("%d",&y[0][1]);
printf ("\nENTER 2ND ROW\n");
scanf ("%d",&y[1][0]);
scanf ("%d",&y[1][1]);
u[0][0]=t[0][0]+y[0][0];
u[0][1]=t[0][1]+y[0][1];
u[1][0]=t[1][0]+y[1][0];
u[1][1]=t[1][1]+y[1][1];

printf ("\nSum\n%d %d\n%d %d",u[0][0],u[0][1],u[1][0],u[1][1]);
}
Snopy Cobra
Snopy Cobra
Admin
Admin

Number of posts : 99
Age : 34
Location : Bahria University Karachi
Reputation : 0
Registration date : 2008-07-31

https://telecompk.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum