Skip to content

Instantly share code, notes, and snippets.

@winhtut
Last active January 2, 2020 06:54
Show Gist options
  • Save winhtut/6667c51870017f80485bfc09cd0ae9c4 to your computer and use it in GitHub Desktop.
Save winhtut/6667c51870017f80485bfc09cd0ae9c4 to your computer and use it in GitHub Desktop.
Lesson 10 Array
#include<iostream>
using namespace std;
int main(){
int data[100]={0};
int number=0;
cout<<"Please enter numbers (1-100)"<<endl;
cin>>number;
for ( int i=0; i<number ; i++){
cout<< i <<" Please enter number :";
cin>>data[i];
cout<<endl;
}
for ( int ii=0; ii<number ; ii++){
if(data[0]<data[ii]){
data[0]=data[ii];
}
}
cout<<"The largest number is "<<data[0]<<endl;
for(int j=0; j<number; j++){
cout<<j<<" data is :"<<data[j]<<endl;
}
return 0;
}
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int arr[50], size, insert, i, pos;
cout<<"Enter Array Size : ";
cin>>size;//5
cout<<"Enter array elements : ";
for(i=0; i<size; i++)
{
cin>>arr[i];
}
cout<<"Enter element to be insert : ";
cin>>insert;//100
cout<<"At which position (Enter index number) ? ";
cin>>pos;//3
// now create a space at the required position
for(i=size; i>pos; i--) //{ 5 , 6, 7, 8, 9, 10}//index 2
{ //3
arr[i]=arr[i-1];//3
}
arr[pos]=insert;//100//pos3
cout<<"Element inserted successfully..!!\n";
cout<<"Now the new array is : \n";
for(i=0; i<size; i++)
{
cout<<arr[i]<<" ";
}
getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int arr[50], size, i, del, count=0;
cout<<"Enter array size : ";
cin>>size;
cout<<"Enter array elements : ";
for(i=0; i<size; i++)
{
cin>>arr[i];
}
cout<<"Enter element to be delete : ";
cin>>del;
for(i=0; i<size; i++)
{
if(arr[i]==del)//3
{
for(int j=i; j<(size-1); j++)//j=3
{
arr[j]=arr[j+1];//4
}
count++;
break;
}
}
if(count==0)
{
cout<<"Element not found..!!";
}
else
{
cout<<"Element deleted successfully..!!\n";
cout<<"Now the new array is :\n";
for(i=0; i<(size-1); i++)
{
cout<<arr[i]<<" ";
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
int main() {
int name[] = { 10,20,30,40,50};
int i = name[3];
printf_s("This is array %d\n", i);
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main(){
int name[7] = { 10,20,30,40,50};
int i = name[6];
printf_s("This is array %d\n", i); // underscore _s ကို ျဖုတ္ေရးႏိုင္သည္
_getch(); // error တက္ေနလ်င္ _ ကို ျဖုတ္ေရးနိုင္သည္။
return 0;
}
#include<stdio.h>
#include<conio.h>
int main() {
int name[5];
int i ;
for (i = 0; i < 10; ++i) {
printf_s("Theis is array %x\n ",name[i]);
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main() {
int name[5] = { 1,2,3,4,5 };
int i ;
for (i = 0; i < 5; ++i) {
printf_s("Theis is array %d\n ",name[i]);
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define SIZE 5
int main() {
int Aname[SIZE];
for (int j = 0; j < SIZE; ++j) {
Aname[j] = 2 + 2 * j;
}
printf_s("%s%13s\n", "Element", "Value");
for (int i = 0; i < SIZE; ++i) {
printf_s("%7u%13d\n", i, Aname[i]);
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define WINHTUT 12
int main() {
int a[WINHTUT] = { 1,3,5,4,7,2,99,16,45,67,89,45 };
int total = 0;
for (int i = 0; i < WINHTUT; ++i) {
total += a[i];
}
printf_s("Total of array element values is %d\n", total);
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define RESPONSES_SIZE 40
#define FREQUENCY_SIZE 11
int main() {
int frequency[FREQUENCY_SIZE] = { 0 };
int responses[RESPONSES_SIZE] = { 2, 3, 2, 3, 4, 2, 3, 2, 3, 10,
2, 2, 3, 3, 2, 10, 3, 3, 2, 2, 2, 2, 2, 2,2, 2, 2, 2, 3, 3,
3, 3, 3, 2, 2, 3, 3, 3, 2, 10 };
for (int answer = 0; answer < RESPONSES_SIZE; ++answer) {
++frequency[responses[answer]];
}
printf_s("\n");
printf("%s%17s\n", "Rating", "Frequency");
for (int rating = 1; rating < FREQUENCY_SIZE; ++rating) {
printf("%6d%17d\n", rating, frequency[rating]);
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define SIZE 5 // array တစ္ခုရဲ႕ size ကို စတင္ေျကျငာေပးျခင္း
int main() {
int n[SIZE] = { 19, 3, 15, 7, 11 };
printf("%s%13s%17s\n", "Element", "Value", "Histogram");
for (int i = 0; i < SIZE; ++i) {
printf("%7u%13d ", i, n[i]);
for (int j = 1; j <= n[i]; ++j) {
printf("%c", '*');
}
puts("");
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 7
int main() {
unsigned int frequency[SIZE] = { 0 };
srand(time(NULL));
for (unsigned int roll = 1; roll <= 60000000; ++roll) {
int face = 1 + rand() % 6;
++frequency[face];
}
printf("%s%17s\n", "Face", "Frequency");
for ( int face = 1; face < SIZE; ++face) {
printf("%4d%17d\n", face, frequency[face]);
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
int main() {
char aung[] = "winhtut";
printf_s("%d", aung[7]);
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define END 8
int main() {
char aung[] = {'w','i','n','h','t','u','t','\0'};
for (int i = 0; i <END; i++)
{
printf_s("%c\n", aung[i]);
}
_getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#define LENGTH 20
int main() {
char gh1[LENGTH];
char gh2[] = "green hackers";
printf("%s","Please enter characters :");
scanf("%19s", gh1);
printf("gh1 is = %s\n",gh1);
printf("gh2 is = %s\n",gh2);
for (int i = 0; i < LENGTH && gh1[i] != '\0'; ++i) {
printf("%c",gh1[i]);
}
getch();
return 0;
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
void func(int arr[], int val);
int main() {
int gh[5] = { 2,3,4,5,6 };
int power;
printf_s("enter power number");
scanf_s("%d", &power);
func(gh, power);
_getch();
return 0;
}
void func(int arr[], int val) {
int i;
for (i = 0; i < 5; i++) {
printf_s("value %d: %f\n", (i + 1), pow(arr[i], val));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment