While the last character in Python is a[-1]
, what would be its equivalent in C? Or how would it be achieved?
Severus Lightwood's questions
I have this code, I want the "sum" function (which I want to add the first and last position of the array) to be applied to a given array. How do I take the last position of the array?
#include <stdio.h>
#define CUBO(a) a*a*a
int suma (int a[]);
int main()
{
int size;
printf("cant ar: ");
scanf("%i",&size);
int ar[size];
for (int i=0; i<size; i++)
{
printf("valror %i: ",i+1);
scanf("%i",&ar[i]);
}
printf("la suma es %i",suma(ar[]));
return 0;
}
int suma(a[]){
int sum;
sum= a[0] + CUBO(a[size-2]);
return sum;
}
The compiler tells me that "size" is not declared in the function, in python it would be a[-1], but how do I do it in C so that it indicates the last position of the array?
I need to add an element to an array as long as it meets a certain condition (eg positive). This is what I have but I don't know how to add it to the array.
void cargar(int a){
int ar[11];
int nu, i;
for (i=0;i<11;i++){
printf("ingrese numero: ");
scanf("%d",&nu);
if (nu>0)
}
}
How do I calculate the two smallest numbers in an array? using a min only helps me to know the smallest not the two smallest
def minimo(a):
mini=a[0]
for m in range (len(n)):
if a[m]<mini:
mini=a[m]
return mini
I have the following numbers in an array: 1 2 7 4 6 7 8 How do I insert the next number of each even number after this one? so I am left with the following: 12 3 74 5 6 7 78 9 .
def par(a):
n2=[]
for i in range(len(n)):
if a[i] % 2 != 0:
n2.append(a[i])
else:
n2.insert(a[i]+1)