Friday, May 21, 2010

Could somebody please help me develop these programs in C language?

1 Twin numbers are those prime numbers that have a difference of 2. Knowing the function int isprime(int n), that returns de value "1" if the number "n" is prime and the value


"0" if the number "n" is not prime, make the funcion void twins(int a,int b) that prints the pairs of twin numbers within the range [a,b].


2. Make a C program that given the salary of "n" number of employees, gives me the average salary. (preferably using arrays) 3. Write a C prgram that, given an array, it inverts the sequence of values on the array. For exmaple, if the array had the values A=[10 3 5 2 3 9 10 4 7 1], the operation inverts the order: A=[1 7 4 10 9 3 2 5 3 10].


4.Write a C program that receives two different arrays, and prints "Yes" if both arrays have the same values in the same positions (if they're identical), and "No", if they're not.





5.Write the function int isprime(int n), that prints the value "1" i "n" is a prime number and the value "0" if "n" is not a prime number

Could somebody please help me develop these programs in C language?
These are really easy programs to write...if this is your homework, I would recommend doing them yourself as you will learn a lot.











I can give you an example of how easy it is:





#2 is ridiculously easy I am assuming "total salary" is given and "number of employees" = n: There are intentional errors in this and parts you have to fill in, but it should give you an idea...





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





void avgSalaries (int salaries[])


{


//count the number of items in the array (brute force)


int count = 0;


for (int i = 0; i == -1; i++)


{


count = i;


isNull = salaries[i];


if(isNull == NULL) {


i = -1;


}


}


//then take the average...


}











...and then some function to get and pass the salaries to avgSalaries...wherever they are








void main()


{


//some way to get the salaries and put them into an array...


//probably from command line...do a google search to find //out how to do this


avgSalaries(salaries[]);


}
Reply:hey!! u want ppl to write them for u??? ther r pretty strait forward...


i can give u da idea to help


1. just check if entered no are prime.. if yes.. find da difference n then see if they lie bet da range given


2. add all da nos in da array in a loop...


sum = sum + a[i].. wher a[i] will be da array..


3. create a loop in reverse like


for(i=9,i%26gt;0,i--).. in this loop print da array


printf(a[i])...


4. for this u call a func compArr(position)


position is da position no of the element to be compared.. now say ... if(a[position] == b[position]) yes...


5. here use da %(mod) operator. divide the no. with all nos lesser than it execpt "1". if any where result is 0.. then its nopt prime.. else prime...good luck!!!!
Reply:this is for 4th problem


#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


int a[5] = {1,2,3,4,5},b[5] = {1,2,3,4,5},i,flag = 1;


for(i=0; i%26lt;=4; i++)


{


if (a[i] != b[i])


flag = 0;


}





if (flag == 0)


printf("\nNo");


else


printf("\nNo");


getch();


}

brandon flowers

No comments:

Post a Comment