Posts

c program to find sum of first n numbers

#include<stdio.h> #inclue<conio.h> void main() { int sum=0,n=1,l; printf("enter the limit"); scanf("%d",&l); while(n<=l) { sum=sum+n; } printf("sum of first %d numbers=%d",l); getch(); }

c program to generate odd numbers up to a limit

#include<stdio.h> #include<conio.h> void main() { int n,i; printf("enter the limit to generate odd nuymber") scanf("%d",&n); printf("generated odd numbers are"); for(i=1;i<n;i++)   if(i%2!=0) printf("%d",i); } getch(); }
CLICK HERE TO DOWNLOAD C++ AFTER DOWNLOADING  OPEN THE DOWNLOADED ZIP FILE CLICK INSTAL FILE THEN TYPE  C AND ENTER THEN ENTER THEN SELECT START INSTALLATION.......

Pyramid Pattern no. 8 using c code

Image
Pyramid Pattern no. 8 using c code /* To print Pyramid Pattern shown below */ #include<stdio.h> int main() { int i,j,n; printf("Enter no. of lines: "); scanf( "%d",&n); //for loop for upper pyramid //for loop for number of lines for(i=1;i<=n;i++) { //for loop for spaces for(j=1;j<=n-i;j++) { printf(" "); } //for loop for stars in first half for(j=1;j<=i;j++) { printf("* "); } //for loop for stars in second half for(j=1;j<i;j++) { printf("* "); } printf("\n"); } //for loop for lower pyramid //for loop for number of lines for(i=1;i<=n-1;i++) { //for loop for spaces for(j=1;j<=i;j++) { printf(" "); } //for loop for stars in first half for(j=1;j<=n-i;j++) { printf("* "); } //for loop for stars in second half for(j=1;j<n-i;j++) { printf("* "); } printf("\n"); } return 0; }

SORT NAMES IN ALPHABETICAL ORDER USING POINTERS

SORT NAMES IN ALPHABETICAL ORDER USING POINTERS #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 5 #define MAX_STRLEN 256 #define MAX_NAMELEN 128 typedef struct {   char *first;   char *last; } Name; void sort(Name *a, int n); Name *nameArray; int main(int argc, char *argv[]) {   int i;   char line[MAX_STRLEN],*p;   nameArray = (Name *)calloc(N,sizeof(Name));   printf("\nEnter %d names (First Last), one per line:\n",N);   for (i = 0; i < N; i++) {     printf("> ");     fgets(line,MAX_STRLEN,stdin);     *(strchr(line,'\n')) = '\0';     if (strlen(line) > 0) {       /*        * Could use some more logic here to verify input.        * This will work for : First Las...

GENERATE AND PRINT FIRST N FIBONACCI NUMBERS

Image
c program to generate, print fibonacci series This program generates Fibonacci series without recursion. You can print as many number of terms of series as desired. C code #include<stdio.h> #include<conio.h>   main ( ) { int n , first = 0 , second = 1 , next , c ;   printf ( "Enter the number of terms " ) ; scanf ( "%d" ,& n ) ;   printf ( "First %d terms of fibonacci series are :- \n " , n ) ;   for ( c = 0 ; c < n ; c ++ ) { if ( c <= 1 ) next = c ; else { next = first + second ; first = second ; second = next ; } printf ( "%d \n " , next ) ; }   getch ( ) ; return 0 ; } Output:

SORT LIST OF NAMES IN ALPHABETICAL ORDER

C Program to sort the list of names of persons in alphabetical order using Bubble sort technique #include<stdio.h> #include<string.h> void main(void) { int i,k,n; char*name[50],*temp=""; printf("\nEnter number of persons:"); scanf("%d",&n); for(i=0;i<n;i++) gets(name[i]); for(k=0;k<(n-1);k++) { for(i=0;i<(n-k-1);i++) { if(strcmp(name[i],name[i+1]>0) { strcpy(temp,name[i]); strcpy(name[i],name[i+1]); strcpy(name[i+1],temp); } } } printf("\nSorted List....\n"); for(i=0;i<n;++i) puts(name[i]); }