basic c programs

02/09/2010 20:00


// C program to count the number of positive, negative and zero number in the given list of numbers.

 

#include<stdio.h>

#include<conio.h>

main()

{

    int npos, nneg, nzero, i, a[25]n;

npos =0;

nneg =0;

nzero =0;

printf(“\n enter the total no.of values in set”);

scanf(“%d”,&n);

printf(“\n enter the elements in set”);

for(i=0;i<n;i++)

{

scanf(“%d”,&a[i]);

}

for(i=0;i<n;i++)

{

 if(a[i]>0)

{

npos+=1;

}

else if(a[i]<0)

{

nneg+=1;

}

else

{

nzero+=1;

}

}

printf(“\n no. of positive nos. in given set:%d”, npos);

printf(“\n no. of negative nos .in given set:%d”, npos);

printf(“\n no. of zeros in given set:%d”, npos);

}

 

// C program for temperature conversion.

 

#include<stdio.h>

#include<conio.h>

main()

{

float c,f;

printf('\n enter the value of temperature in farenheit");

scanf("%f",&f);

c=((f-32)*(5/9));

printf("\n corresponding celsius value:%f",c);

}

}

 

//to print n prime nos.

 

#include<stdio.h>

#include<conio.h>

main()

{

int i,n;

printf("\n enter the range n");

scanf("%d", &n);

for(i=2;i<=n; i++)

{

if(n%i==0)

{

printf("\n %d is not prime",n);

}

if(n/i==1)

{

printf("\n %d is prime",n);

}

}