#SP6_24_Feb_2018 Please solve this problem. Enter N: 5 a B B c c c D D D D e e e e e

Nested For Loop

HOME Forums Forum Nested For Loop

This topic contains 5 replies, has 1 voice, and was last updated by  Meng Meng 1 year, 4 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #913 Reply

    RaksmeyChea

    #SP6_24_Feb_2018
    Please solve this problem.

    Enter N: 5
    a
    B B
    c c c
    D D D D
    e e e e e

    #914 Reply

    Chheang Sopheaktra
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
    	int n;
    	cout<<"Input N : ";cin>>n;
            char letter[26]={'a','B','c','D','e','F','g','H','i','J','k','L','m','N','o','P','q','R','s','T','u','V','w','X','y','Z'};
    	for(int i=1;i<=n;i++){
    		for(int j=i;j>0;j--){
    			cout<<letter[i-1]<<" ";
    		}
    		cout<<endl;
    	}
       getch();
    }
    
    #915 Reply

    Chhin
    #include<iostream.h>
    #include<conio.h>
    void main ()
    {
    	int n,a=97,b=31;
       cout<<"Enter N="; cin>>n;
       int c=a-b;
       for(int i=1;i<=n;i++)
       {
       	if(i%2!=0)
          {
          	for(int j=1;j<=n;j++)
             {
             	if(j<=i)
                cout<<char(a)<<" ";
                else
                cout<<"  ";
             }
             a+=2;
             cout<<endl;
          }
          else
          {
          	for(int j=1;j<=n;j++)
             {
             	if(j<=i)
                cout<<char(c)<<" ";
                else
                cout<<"  ";
             }
             c+=2;
             cout<<endl;
          }
       }
       getch();
    }
    <\pre>
    #916 Reply

    Nob Vibol
    #include<iostream.h>
    #include<conio.h>
    void main()
    {
       char ch1=96,ch2=64;
       int n;
       cout<<"Enter N:";cin>>n;
       for (int i=1;i<=n;i++)
          {
          	for (int j=1;j<=i;j++)
    
          	       if(i%2!=0)
                   {
                   	ch1=96+i;
                   	cout<<ch1;
                   }
                   else
                   {
                   	ch2=64+i;
                   	cout<<ch2;
                   }
          cout<<endl;
          }
          getch();
    }
    
    #917 Reply

    Voeurn Sothavith
    #include<iostream>
    #include<conio.h>
    void main()
    {
    	int n,odd=96,even=64;
    	cout << "N : ";cin >>n;
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=i;j++)
    		{
    			if(i%2==0)
    			{
    				int b = even+i;
    				cout << (char)b << " ";
    			}
    			else
    			{
    				int a = odd+i;
    				cout << (char)a << " ";
    			}
    		}
    		cout << endl << endl;
    	}
     	getch();
    }
    
    #970 Reply

    Meng Meng

    ` static void Main()
    {
    Write(“Input number of element: “);
    int n = int.Parse(ReadLine());

    int[] a = new int[n];
    for (int i = 0; i < n; i++)
    {
    Write(“Input A[{0}]: “, i);
    a[i] = int.Parse(ReadLine());
    }

    Array.Sort(a);

    WriteLine(“After sorted this array: “);
    int j = 0;
    foreach (int e in a)
    {
    WriteLine(“A[{0}]: {1}”, j, a[j]);
    j++;
    }

    for (int i = 0; i < n; i++)
    {
    int time = 1;
    for (j = i + 1; j < n; j++)
    {
    if (a[i] == a[j])
    {
    time += 1;
    }
    }
    if (time > 1)
    {
    WriteLine(“{0} occurs {1} times.”, a[i], time);
    i += time – 1;
    }
    else
    {
    WriteLine(“{0} occurs {1} times.”, a[i], time);
    }
    }

    ReadKey();
    }

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Nested For Loop
Your information: