Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
#include <stdio.h>
void main()
{
int n, m, digit, sum;
sum=0;
printf("\n enter a positive integer");
scanf("%d", &n);
m=n;
while (n>0)
{
digit = n%10;
sum= sum+digit;
n=n /10;
}
n=m;
printf("\n sum of digits of given number %d = %d", n, sum);
}
#include <stdio.h>
int main(){
short image[60][40]; // the array to store the text image
FILE * infile = fopen("inimage.txt", "r"); // text image input file
for(int i = 0; i < 60; i++){
for(int j = 0; j < 40; j++){
fscanf(infile, "%d\t", &image[i][j]); // this will read an integer and store it in the array, then read a tab
}
}
short quick_mask[3][3] = { {-1, 0, -1}, {0, 4, 0},{-1, 0, -1} }; // this is the mask which will be convoluted with the image array
short store = 0; // integer to store each output element
FILE * outfile = fopen("outimage.txt", "w"); // text image output folder
// nested for loop to perform the convolution
for(int i = 0; i < 60; i++){
for(int j = 0; j < 40; j++){
if(i < 58 && j < 38) // to skip the edge of the text image
{
// convolution calculation ( mask * image)
store = (image[i-1+1][j-1+1] * quick_mask[0][0]) +
(image[i-1+1][j+1] * quick_mask[0][1]) +
(image[i-1+1][j+1+1] * quick_mask[0][2]) +
(image[i+1][j-1+1] * (quick_mask[1][0]) +
(image[i+1][j+1]) * quick_mask[1][1]) +
(image[i+1][j+1+1] * quick_mask[1][2]) +
(image[i+1+1][j-1+1] * quick_mask[2][0]) +
(image[i+1+1][j+1] * quick_mask[2][1]) +
(image[i+1+1][j+1+1] * quick_mask[2][2]) ;
}
else{
// edges will be always 0
store = 0;
}
if(store < 0) store = 0; // min color is black (0)
else if(store > 255) store = 255; // max color is white ( 255)
fprintf(outfile, "%d\t", store); // write the output into a file
}
fprintf(outfile, "\n"); // add a new line each row
}
return 0; // end of the program
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int val1=0;
int val2=0;
printf("Enter two numbers to be multiplied:");
fflush(stdin);
scanf("%f,%f",&val1, &val2);
printf("\nThe product of these two numbers is: ""%f", val1*val2 );
system("pause");
return 0;
}
#include <stdio.h>
void fun(int arr[])
{
int i;
int arr_size = sizeof(arr)/sizeof(arr[0]);
printf("sizeof arr %d",sizeof(arr));
printf("\n size of first element %d",sizeof(arr[0]));
for (i = 0; i < arr_size; i++)
{
printf("%d ", arr[i]);
}
}
int main()
{
int i;
int arr[4] = {10, 20 ,30, 40};
fun(arr);
}
%{
#include<stdio.h>
int vowels=0;
int cons=0;
%}
%%
[aeiouAEIOU] {vowels++;}
[a-zA-Z] {cons++;}
%%
int yywrap()
{
return 1;
}
main()
{
printf("Enter the string.. at end press ^d\n");
yylex();
printf("No of vowels=%d\nNo of consonants=%d\n", vowels,cons);
}