Posts

Showing posts with the label Programs library

C Program to convert string into ASCII values in c programming language

#include<stdio.h> int main(){ char str[100]; int i=0; printf("Enter any string: "); scanf("%s",str); printf("ASCII values of every characters of string: "); while(str[i]) printf("%d ",str[i++]); return 0; } Enter any string:ankit c guru ASCII values of every characters of string: 97 110 107 105 116

C program to change Upper case to lower case

/*by ankit gehlot website:ankitcguru.blogspot.com/ */ #include<stdio.h> int main(){ char str[20]; int i=0; printf("Enter any string :"); scanf("%s",str); while(str[i]!='\0'){ if(str[i]>=65&&str[i]<=97){ str[i]=str[i]+32;}i++; } printf("\nThe string in lowercase is :%s ",str); return 0; } Output:- Enter any string :ANKIT The string in lowercase is :ankit

C program to change lower case to upper case

/*by ankit gehlot website:ankitcguru.blogspot.com/ */ #include<stdio.h> int main(){ char str[20]; int i=0; printf("Enter any string :"); scanf("%s",str); while(str[i]!='\0'){ if(str[i]>=97&&str[i]<=122){ str[i]=str[i]-32;}i++; } printf("\nThe string in Upper case is :%s",str); return 0; } Output:- Enter any string :ankit The string in lowercase is :ANKIT

C program to print length of string

         C program to print length of string include<stdio.h> void main(){ char str[15]; int=0; printf("Enter any string :\t");  scanf("%s",&str); while(str[i]!='\0') { i++; printf("\nLength of string :\t%d",i); getch(); } Output:- Enter any string :      ankit c guru Length of string :      12 Note:- Compiler will also count blank spaces between words while compiling.

C# program to sum members of array

           C# program to sum members of Array /*website: http://ankitcguru.blogspot.com/ *programmer:ankit gehlot*/ #include<stdio.h> #include<conio.h> void main() { int sum=0,i; int num[10]; for(i=0;i<10;i++){ printf("enter value in array:"); scanf("%d",&num[i]); sum=sum+num[i]; } printf("sum of array:%d",sum); getch(); } Output:-   enter value in array:1 enter value in array:2 enter value in array:3 enter value in array:4 enter value in array:5 enter value in array:6 enter value in array:7 enter value in array:8 enter value in array:9 enter value in array:10 sum of array:55

Write a c program which takes password from users

// author:ankit gehlot //website:http://ankitcguru.blogspot.com/   #include<stdio.h> #define MAX 500 int main(){ char password[MAX]; char p; //character declaration int i=0;//intiger declaration printf("Enter the password:"); while((p=getch())!= 13)//while loop { password[i++] = p; printf("*"); } password[i] = '\0'; if(i<6) //condition printf("\nWeak password"); printf("\nYou have entered: %s",password); return 0;//return value }

c program of structure with array

#include<conio.h> #include<stdio.h> struct stu { int roll,h,en,s,sum,per; char name[20];}; void main() {struct stu e[10]; int i,sum,per; clrscr(); for(i=0;i<=1;i++) { printf("enter emp no:\t"); scanf("%d",&e[i].roll); printf("enter name:\t"); scanf("%s",e[i].name); printf("enter marks of hindi,english,science:\n"); scanf("%d%d%d",e[i].h,e[i].en,e[i].s); sum=e[i].h+e[i].en+e[i].s; per=(sum*100)/3;} printf("Emp no.\t\tName\tHindi\tEnglish\tScience\tTotal\tPercentage\n"); for(i=0;i<=10;i++) { printf("%d\t\t%s\t%d\t%d\t%d\t%d\t%d\n",e[i].roll,e[i].name,e[i].h,e[i].en,e[i].s,sum,per); } getch(); }

Revers a string

#include<stdio.h> #include<string.h> main() {    char arr[100];    printf("Enter a string to reverse\n");    gets(arr);    strrev(arr);    printf("Reverse of entered string is \n%s\n",arr);    getch(); }

c program to print Floyd's triangle

#include <stdio.h>   int main() { int n, i, c, a = 1;   printf("Enter the number of rows of Floyd's triangle to print\n"); scanf("%d", &n);   for (i = 1; i <= n; i++) { for (c = 1; c <= i; c++) { printf("%d ",a); a++; } printf("\n"); }   return 0; }

c program to print Pascal triangle

#include <stdio.h>   int main() { int n, i, c, a = 1;   printf("Enter the number of rows of Floyd's triangle to print\n"); scanf("%d", &n);   for (i = 1; i <= n; i++) { for (c = 1; c <= i; c++) { printf("%d ",a); a++; } printf("\n"); }   return 0; }

c program for String concatenation

#include<stdio.h>   void concatenate_string(char*, char*);   main() { char original[100], add[100];   printf("Enter source string\n"); gets(original);   printf("Enter string to concatenate\n"); gets(add);   concatenate_string(original, add);   printf("String after concatenation is \"%s\"\n", original);   return 0; }   void concatenate_string(char *original, char *add) { while(*original) original++;   while(*add) { *original = *add; add++; original++; } *original = '\0'; }

Matrix multiplication in c

#include <stdio.h>   int main() { int m, n, p, q, c, d, k, sum = 0; int first[10][10], second[10][10], multiply[10][10];   printf("Enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("Enter the elements of first matrix\n");   for ( c = 0 ; c < m ; c++ ) for ( d = 0 ; d < n ; d++ ) scanf("%d", &first[c][d]);   printf("Enter the number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q);   if ( n != p ) printf("Matrices with entered orders can't be multiplied with each other.\n"); else { printf("Enter the elements of second matrix\n");   for ( c = 0 ; c < p ; c++ ) for ( d = 0 ; d < q ; d++ ) scanf("%d", &second[c][d]);   for ( c = 0 ; c < m ; c++ ) { for ( d = 0 ; d < q ; d++ ) { for ( k = 0 ; k < p ; k++ ) ...

Factorial program in c

#include <stdio.h>   int main() { int c, n, fact = 1;   printf("Enter a number to calculate it's factorial\n"); scanf("%d", &n);   for (c = 1; c <= n; c++) fact = fact * c;   printf("Factorial of %d = %d\n", n, fact);   return 0; }

c program to print date

#include<stdio.h> #include<conio.h> #include<dos.h>   main() { struct date d;   getdate(&d);   printf("Current system date is %d/%d/%d",d.da_day,d.da_mon,d.da_year); getch(); return 0; }

c program to delete a file

#include<stdio.h>   main() { int status; char file_name[25];   printf("Enter the name of file you wish to delete\n"); gets(file_name);   status = remove(file_name);   if( status == 0 ) printf("%s file deleted successfully.\n",file_name); else { printf("Unable to delete the file\n"); perror("Error"); }   getch(); }

c program to print Fibonacci series

/* Fibonacci Series c language */ #include<stdio.h>   main() { int n, first = 0, second = 1, next, c;   printf("Enter the number of terms\n"); 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); }   return 0; }

c program to display your ip adress

#include<stdlib.h>   main() { system("C:\\Windows\\System32\\ipconfig"); system("pause");   return 0; }

c program to shutdown your computer

#include <stdio.h> #include <stdlib.h>   main() { char ch;   printf("Do you want to shutdown your computer now (y/n)\n"); scanf("%c",&ch);   if (ch == 'y' || ch == 'Y') system("C:\\WINDOWS\\System32\\shutdown /s");   return 0; }

C program for palindrome without using string functions

#include <stdio.h> #include <string.h>   main() { char text[100]; int begin, middle, end, length = 0;   gets(text);   while ( text[length] != '\0' ) length++;   end = length - 1; middle = length/2;   for( begin = 0 ; begin < middle ; begin++ ) { if ( text[begin] != text[end] ) { printf("Not a palindrome.\n"); break; } end--; } if( begin == middle ) printf("Palindrome.\n");   return 0; }

c program to check whether input alphabet is a vowel or not

   C program to check whether input  alphabet is a vowel or not   #include <stdio.h>   main() { char ch;   printf("Enter a character\n"); scanf("%c", &ch);   if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U') printf("%c is a vowel.\n", ch); else printf("%c is not a vowel.\n", ch);   getch(); }