Posts

Write a program to sum N numbers using command line arguments. The following program must be executed in the command prompt or with the arguments set in the environment.

/* Write a program to sum N numbers using command line arguments*/ #include <stdio.h> #include <ctype.h> void main(char *argv[],int argc) {     int i,s=0;     for(i=1;i<argc;i++)     {         printf("Value at %u is %s\n",argv[i],argv[i]);         s+=atoi(argv[i]);     }     printf("Sum is %d\n",s);     getch(); }

Write a program to show the usage of storage class:register.

/* Write a program to show the usage of storage class:register*/ #include <stdio.h> #include<time.h> void main() {     float v1;     register float v2;     clock_t s1,e1,s2,e2;     s1=clock();     for(v1=0.01;v1<=1000;v1+=0.01)     {         printf("%8.2f ",v1);     }     e1=clock();     s2=clock();       for(v2=0.01;v2<=1000;v2+=0.01)     {         printf("%8.2f ",v2);     }     e2=clock();     printf("\nNormal processing : %f\n",(double)(e1-s1)/CLOCKS_PER_SEC);     printf("\nRegister processing : %f\n",(double)(e2-s2)/CLOCKS_PER_SEC);       getch(); }

Write a program to show the usage of storage class:static.

/* Write a program to show the usage of storage class:static*/ #include <stdio.h> void disp() {     static int i=5;     printf("I=%d\n",i);     i++; } void main() {     disp();     disp();     disp();     getch(); }

Write a program to show the usage of storage class:extern.

 /* prog38.h*/ int i=50; /*prog38.c*/ /* Write a program to show the usage of storage class:extern*/ #include "prog38.h" #include <stdio.h> extern int i; void main() {     printf("I=%d\n",i);     getch(); }

Write a program to show the usage of storage class:auto.

/* Write a program to show the usage of storage class:auto*/ #include <stdio.h> void disp() {       auto int i=20;     printf("I = %d\n",i);     i++; }   void main() {     disp();     disp();     disp();     getch(); }

Write a program to find the factorial of the given number using preprocessor directive #include. The following program has two source files.

 /*prog36.h*/ long factorial(int x) {     if (x<1)     {         return 1;     }     return x*factorial(x-1); } /*prog36.c*/ /* Write a program to find the factorial of the given number using preprocessor directive #include*/ #include <stdio.h> #include "prog36.h" void main() {     int n;     long fact;     printf("Enter the number : ");     scanf("%d",&n);     fact=factorial(n);     printf("Factorial is %ld\n",fact);     getch(); }

Write a program to accept radius of a circle and find the circumference and area using preprocessor directive #define.

/* Write a program to accept radius of a circle and find the circumference and area using preprocessor directive #define*/ #include <stdio.h> #define PI 3.1415 void main() {     float radius,circum,area;      printf("Enter the radius of a circle : ");     scanf("%f",&radius);     circum=2*PI*radius;     area=PI * radius * radius;     printf("Circumference : %8.3f\n",circum);     printf("Area           : %8.3f\n",area);     getch(); }