Posts

Showing posts from March 11, 2018

C program to delete the written word using string function

Image
#include <stdio.h> #include <string.h> int main() {     int i, j = 0, k = 0, count = 0;     char str[100], key[20];     char str1[10][20];     printf("enter string:");     scanf("%[^\n]s",str); /* Converts the string into 2D array */        for (i = 0; str[i]!= '\0'; i++)     {         if (str[i]==' ')         {             str1[k][j] = '\0';             k++;             j = 0;         }         else         {             str1[k][j] = str[i];             j++;         }     }     str1[k][j] = '\0';     printf("Which word to delete ?:");     scanf("%s",&key); /* Compares the string with given word */        for (i = 0;i < k + 1; i++)     {         if (strcmp(str1[i], key) == 0) //When both are same then override the current row with next row and so on upto the last row.         {             for (j = i; j < k + 1; j++)             strcpy(str1[j], str1[j + 1])

C Program To Find Prime Number From Inputted Numbers | C Programming

Image
C Program To Find Prime Number From Inputted Numbers #include<stdio.h> int main() {  int n,i,j,c=0,a[100];  printf("How many numbers to be inputed ?");  scanf("%d",&n);  printf("\nEnter the numbers:\n");  for(i=1;i<=n;i++)  {   scanf("%d",&a[i]);  }  printf("\n\nThe prime numbers are:  ");  for(i=1;i<=n;i++)  {      c = 0;      for(j=1; j<=a[i]; j++)         {             if(a[i]%j==0)             {                 c=c+1;             }         }         if(c==2)         {             printf("%d\t",a[i]);         }  }  return 0; } OUTPUT

C Program To Show Square Of Numbers And Find Their Sum | C Programming

Image
C Program To Show Square Of Numbers And Find Their Sum #include<stdio.h> int main() { int i=1,n,sq,sum=0; printf("Enter number:\n"); scanf("%d",&n); printf("number\tsquare\n"); while(i<=n) { sq=i*i; printf("%d\t%d\n",i,sq); i++; sum+=sq; } printf("sum is %d",sum); return 0; } OUTPUT

File Handling in C Programming | C Programming

Image
File Handling in C Programming | C Programming Language     C supports a number of functions that have the ability to perform basic file operations, which include:    1. Naming a file    2. Opening a file    3. Reading from a file    4. Writing data into a file    5. Closing a file   

C program to calculate Simple Interest using function | C Programming

Image
Basic Concept Of Function A function is a block of code that performs a specific task. Every C program has at least one function, which is main(), and all the most trivial programs can define additional functions. Function can also be defined as the idea to put some repeatedly done task together by making block of statement which helps while instead of writing the same block of code again and again for different inputs, we can call the same block of statement in the program. Note: If you want to know more about C function Click Here: C program to calculate Simple Interest using function:- #include<stdio.h> int calculate(); int main() { float si; si=calculate(); printf("The Simple Intrest of given data is %.2f",si); return 0; } int calculate() { float principal, rate, time, si; printf("Enter the Principal, Rate and Amount Respectively:-\n"); scanf("%f%f%f",&principal,&rate,&time); si=(principal*rate*time)/100; ret