WAP of C Language that accepts the size of Array and Stores the Element in num Array

Array

Statement of C Program: This Program accepts n Integers and stores them in an Array called num. It also prints them:

#include<stdio.h>
#include<conio.h>
void main()
{
int num[20];
int n , i ;
clrscr();
printf(" Enter the size of an Array\n");
scanf("%d" , &n);

printf(" Enter the elements\n");

for(i = 0 ; i<n ; i++)
{
scanf("%d" , num[i]);
}

printf(" Array:\n ");

for(i = 0 ; i<n ; i++)
{
printf(" num[%d] = %d\n" , i , num[i]);
}
}                                                  /* End of main() */


 Output:
 Enter the size of an Array
 5
 Enter the elements
 10
 20
 30
 40
 50
 Array:
 num[0] = 10
 num[1] = 20
 num[2] = 30
 num[3] = 40
 num[4] = 50


Explanation of the Program:

  • Array declaration: 
Like other variables, Array also needs to be declared so that Compiler will know what kind of an Array and how large an Array we want. This is done with the statement:


      int num[20];      


  1. int specifies the type of the variable. 
  2. num specifies the name of variable.
  3. [20] , The number 20 tells how many elements of the type int will be in our Array. This number is often called 'dimension' of the Array.
  4. The bracket [ ] tells the compiler that we are dealing with Array.
  5. num[15] is not the 15th element of the Array but the 16th element. 
  6. The number with in the square brackets also specifies the element's position in the Array.
  • Entering Data into an Array:
             for(i = 0 ; i<n ; i++)
             {
             scanf("%d" , num[i]);
             }

  • Reading Data from an Array:
            for(i = 0 ; i<n ; i++)
            {
            printf(" num[%d] = %d\n" , i , num[i]);
            }


                                                                     That's All


0 Response to "WAP of C Language that accepts the size of Array and Stores the Element in num Array"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag