Thursday 27 May 2021

C arrays problems

 

#include <stdio.h>

int main()
{

    int arry[10]={25,56,25,2,3,4,7,7,9,10};
    int *ptr;
    ptr = &arry[0];
     ptr++;
     ptr++;
    printf("the value of element is %d",*ptr);

    return 0;
}


#include <stdio.h>

int main()
{

    int array[10];
    int *ptr;
    ptr = array;
    ptr = ptr + 2;
    if (ptr == &array[2])
    {
        printf("the pointer point to same add");
    }
    else
    {
        printf("the pointer doesn't  point to same add");
    }

    return 0;
}


#include <stdio.h>

int main()
{

    int s[3];
    printf("the value is %d",*(s+0));

    return 0;
}


# include<stdio.h> 

 int main(){ 
int mul[10];
for (int i = 0i < 10i++)
{
    mul[i]=5*(i+1);

}
for (int i = 0i < 10i++)
{
    printf("5*%d=%d\n",i+1,mul[i]);
    
}

     
     return 0
}



#include <stdio.h>

int main()
{

    int number;
    printf("Enter the value of table U want?:");
    scanf("%d", &number);
    int mul[10];
    for (int i = 0i < 10i++)
    {

        mul[i] = number * (i + 1);
    }
    for (int i = 0i < 10i++)
    {

        printf("the value of table %d * %d = %d \n"number, (i + 1), mul[i]);
    }

    return 0;
}


#include <stdio.h>
void reverse(int *arrayint n)
{
    int temp;
    for (int i = 0i <( n / 2); i++)
    {
        temp = array[i];
        array[i] = array[n - i - 1];
        array[n - i - 1] = temp;
    }
}
int main()
{
    int array[7] = {1234567};
    reverse(array7);
    for (int i = 0i < 7 ; i++)
    {
        printf("the value is %d\n",array[i]);
    }

    return 0;
}


# include<stdio.h> 
void count(int *arr,int n){
   
    

}
 int main(){ 

     int arr[10];
     count(arr,10);
     return 0
}


#include <stdio.h>

int main()
{
    int i,j;
    int mul[3][10];
    for (i = 0; i < 3; i++)
    {
       for ( j = 0; j< 10; i++)
       {
           mul[i][j]=2*(j+1);
           mul[i][j]=7*(j+1);
           mul[i][j]=9*(j+1);


       }
       
    }
    for (i = 0; i < 3; i++)
    {
       for ( j = 0; j< 10; i++)
       {
         printf("the value of %d *%d = %d \t \t ",2,(j+1),mul[i][j]);
         printf("the value of %d *%d = %d \t \t ",7,(j+1),mul[i][j]);
         printf("the value of %d *%d = %d \t \t ",9,(j+1),mul[i][j]);


       }
       
    }
    

    return 0;
}



#include <stdio.h>

int main()
{
    int marks[3][3];
    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            printf("Enter the marks of student %d and subject %d:"i + 1j + 1);
            scanf("%d", &marks[i][j]);
        }
    }

    for (int i = 0i < 3i++)
    {
        for (int j = 0j < 3j++)
        {
            printf("the marks is %d \n",marks[i][j]);
           
        }
    }


    return 0;
}



# include<stdio.h> 

 int main(){ 
int marks[4];
for (int i = 0; i < 5; i++)
{
    printf("Enter the marks of students %d:",i+1);
    scanf("%d",&marks[i]);
}
for (int i = 0; i < 5; i++)
{
    printf(" the value   of marks is : %d \n",marks[i]);
   
}
     
     return 0
}



#include <stdio.h>

int main()
{

    int array[] = {25657895200};
    int *ptr;
    // ptr = array[0];
    ptr= array;
    for (int i = 0; i < 5; i++)
    {
        printf("the value of elments %d is %d \n",i+1,*(ptr+i));
    }
    
    return 0;
}



#include <stdio.h>

int main()
{
    int arry[]={25,65,85,98,748};
    for (int i = 0i < 5i++)
    {
        printf("the value of element %d is %d \n",i+1,arry[i]);
    }
    

    return 0;
}


#include <stdio.h>

int main()
{
    int marks[4];
    printf("Enter the marks of students:");
    scanf("%d",&marks[0]);
    printf("Enter the marks of students:");
    scanf("%d",&marks[1]);
    printf("Enter the marks of students:");
    scanf("%d",&marks[2]);
    printf("Enter the marks of students:");
    scanf("%d",&marks[3]);
    printf("Enter the marks of students:");
    scanf("%d",&marks[4]);

    printf("You have Entered the marks %d %d %d and %d ",marks[0],marks[1],marks[2],marks[3],marks[4]);


    return 0;
}



#include <stdio.h>

int main()
{
    int arr[3][2];
    

    return 0;
}



#include <stdio.h>

int main()
{
    int arr[3][4][5];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            for (int k = 0; k < 5; k++)
            {
                printf("the add of arr[%d][%d][%d] is %d \n",i,j,k,&arr[i][j][k]);
            }
            
        }
        
    }
    

    return 0;
}



#include <stdio.h>

int main()
{

int marks[5];
int *ptr;
ptr=marks;
for (int  i = 0; i < 5; i++)
{
    printf("Enter the marks of student %d :\n",i+1);
    scanf("%d",ptr);
    ptr++;
}
for (int  i = 0; i < 5; i++)
{
    printf("the marks of student %d : %d \n",i+1,marks[i]);
    
}

    return 0;
}



#include <stdio.h>
void printarr(int ptr[]int n)
{
    for (int i = 0i < ni++)
    {
        printf("the value of elemnts %d is %d \n"i + 1ptr[i]);
    }
    ptr[2] = 520;
}
int main()
{
    int arr[5] = {12345};
    printarr(arr5);
    printf("%d"arr[2]);
    printarr(arr5);

    return 0;
}



#include <stdio.h>

int main()
{
    int marks[4];
    printf("Enter the marks of student 1:");
    scanf("%d",&marks[0]);
    printf("Enter the marks of student 2:");
    scanf("%d",&marks[1]);
    printf("Enter the marks of student 3:");
    scanf("%d",&marks[2]);
    printf("Enter the marks of student 4:");
    scanf("%d",&marks[3]);
    printf("The marks of students is %d %d %d and %d",marks[0],
    marks[1],marks[2],marks[3]);

    

    return 0;
}



#include <stdio.h>
void printTable(int *mulTableint numint n)
{
  printf("the multiplication table of %d \n  ", num);
  for (int i = 0; i < n; i++)
  {
    mulTable[i] = num * (i + 1);
  }
  for (int i = 0; i < n; i++)
  {
  printf("%d*%d=%d\n", num, (i + 1), mulTable[i]);
  }
  printf("*****************************************\n \n ");
}
int main()
{

  int mulTable[3][10];
  printTable(mulTable[0], 210);
  printTable(mulTable[1], 710);
  printTable(mulTable[2], 910);

  return 0;
}



#include <stdio.h>

int main()
{
    int n_student;
    int n_subject;
    printf("Enter the no of student:");
    scanf("%d", &n_student);
    printf("Enter the no of subject:");
    scanf("%d", &n_subject);
    int marks[n_student][n_subject];
    for (int i = 0i < n_studenti++)
    {
        for (int j = 0j < n_subjectj++)
        {
            printf("Enter the marks of student %d in subject %d:"i + 1j + 1);
            scanf("%d",&marks[i][j]);
        }
    }
    for (int i = 0i < n_studenti++)
    {
        for (int j = 0j < n_subjectj++)
        {
            printf("the marks of student %d in subject %d:%d\n"i + 1j + 1,marks[i][j]);
            
        }
    }

    return 0;
}



#include <stdio.h>
void positiveCount(int ptr[]int n)
{
    int n_integer = 0;
    for (int i = 0; i < n; i++)
    {
        if (ptr[i] > 0)
        {

            n_integer++;
        }
    }
    printf("No . of Positive integers are %d", n_integer);
}
int main()
{
    int arr[16] = {-1, -2, -30123456,-4,-5,54,-56,96,-85};
    positiveCount(arr, 16);

    return 0;
}



#include <stdio.h>
void printTable(int *mulTableint numint n)
{

    for (int i = 0; i < n; i++)
    {
        mulTable[i] = num * (i + 1);
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d*%d=%d \n", num, (i + 1), mulTable[i]);
    }
}
int main()
{
    int m, n, num;
    printf("Enter the m rows :\n");
    scanf("%d", &m);
    printf("Enter the n column :\n");
    scanf("%d", &n);
    int mulTable[m][n];
    printf("Enter the which munber Table U want:\n");
    scanf("%d", &num);
    for (int i = 0; i < m; i++)
    {
        printTable(mulTable[m], num, n);
        
        printf("Enter the which number Table U want:\n");
        scanf("%d", &num);
        
        
        
        
    }

    return 0;
}



#include <stdio.h>

int main()
{
  int arr[3];
  int *ptr;
  ptr = arr;
  if (ptr == arr)
  {
    printf("the add lies in same add \n");
  }
  else
  {
    printf("the add lies in diff add");
  }

  return 0;
}



#include <stdio.h>

int main()
{
    int marks[5];
    for (int i = 0; i < 5; i++)
    {
        printf("Enter the marks of student %d :", i + 1);
        scanf("%d", &marks[i]);
    }
    for (int i = 0; i < 5; i++)
    {
        printf("the marks of student %d  is %d \n", i + 1marks[i]);
    }

    return 0;
}



# include<stdio.h> 
void reverse(int *arr,int n){
    int temp;
    for (int i = 0; i < (n/2); i++)
    {
      temp=arr[i];
      arr[i]=arr[n-i-1];
      arr[n-i-1]=temp;
    }
    
}
 int main(){ 
     int arr[7]={1,2,3,5,6,7,8};
     reverse(arr,7);
     for (int i = 0; i <7; i++)
    {
      printf("the value is %d \n",arr[i]);
    }

     
     return 0
}

No comments:

Python if / else

 Python if / else a1 = int ( input (" Enter the number: \n ")) a2 = int ( input (" Enter the number: \n ")) a3 = int ( i...