Professional Documents
Culture Documents
Day 3
Day 3
#include<stdio.h>
void helloworld(); //function declaration
Int main()
{
helloworld(); //function call
Return 0;
}
Doubling a number:
#include<stdio.h>
int doubling(int); //function declaration
int main()
{
int a,b;
printf(“Enter the number to be doubled”);
scanf(“%d”,&a);
b=doubling(a); //function call
return 0;
}
Square of a number:
#include<stdio.h>
int square(int); //function declaration
int main()
{
int a,b;
printf(“Enter the number to be squared”);
scanf(“%d”,&a);
b=square(a); //function call
return 0;
}
Factors of a number:
#include <stdio.h>
Void factors(int);
int main()
{
int number;
#include <stdio.h>
int main() {
int array[10];
int loop,i;
printf(“enter the number of integers”);
scanf(“%d”,&loop); //get the number of elements
printf(“Enter number the %d numbers”, loop);
for(i=0;i<loop;i++)
scanf("%d ", array[i]); //get the elements in order
return 0;
}
#include <stdio.h>
int main() {
int array[10];
int loop,i,n;
printf(“enter the number of integers”);
scanf(“%d”,&loop); //get the number of elements
printf(“Enter number the %d numbers”, loop);
for(i=0;i<loop;i++)
scanf("%d ", array[i]); //get the elements in order
Printf(“enter the index”);
scanf(“%d”,&n);
printf(“the adjacent numbers are %d and %d”,
array[n-1],array[n+1]);
//printing adjacent numbers without performing check
Return 0;
}
#include <stdio.h>
void main()
{
long num, decimal_num, remainder, base = 1, binary = 0, no_of_1s
= 0;
#include <stdio.h>
void main()
int array[10];
int i;
printf(“%d\n”,array[i]);
int next, i, j;
next = -1;
{
if (arr[i] > arr[j]) //condition for smallest
integer
next = arr[j];
break;
int main()
int n ;
return 0;
Session 3
#include <stdio.h>
void main()
{
int i,j,k,arr1[10][10],rsum[10],csum[10],n;
Transpose of a matrix:
#include <stdio.h>
int main()
scanf("%d", &matrix[c][d]);
transpose[d][c] = matrix[c][d];
printf("Transpose of the matrix:\n");
printf("%d\t", transpose[c][d]);
printf("\n");
return 0;
#include <stdio.h>
int main()
int m, n, c, d, matrix[10][10];
printf(“%d”, matrix[0][d];
printf(“%d”, matrix[c][0];
printf(“%d\n”, matrix[c][n];
#include<stdio.h>
int i, j;
return 1;
int main()
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}};
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}};
if (areSame(A, B))
else
return 0;
}
Session-4
#include <stdio.h>
int main()
{
char s[1000];
int i;
#include <string.h>
void main()
char s[200];
int count = 0, i;
scanf("%[^\n]s", s);
for (i = 0;s[i] != '\0';i++)
count++;
#include <stdio.h>
int main()
int c = 0, count = 0;
char s[1000];
printf("Input a string\n");
gets(s);
count++;
c++;
}
return 0;
#include <stdio.h>
#include <conio.h>
#include<string.h>
void main()
char a[80],b[80];
int i,j,t;
clrscr();
gets(a);
fflush(stdin);
gets(b);
printf("Common characters are :\n");
for(i=0;a[i]!='\0';i++)
for(j=i-1;j>=0;j--)
if(a[i]==a[j])
break;
if(j==-1)
for(t=0;b[t]!='\0';t++)
printf("%c",a[i]);
break;
getch();
#include <stdio.h>
int main()
{
char s1[100], s2[100], i, j;
printf("Enter first string: ");
scanf("%s", s1);
s1[i] = '\0';
printf("After concatenation: %s", s1);
return 0;
}
#include<stdio.h>
#include<conio.h>
int main()
{
char str[100],temp;
int i,j;
clrscr();
printf("Enter the string :");
gets(str);
printf("%s in ascending order is -> ",str);
for(i=0;str[i];i++)
{
for(j=i+1;str[j];j++)
{
if(str[j]<str[i])
{
temp=str[j]; //simple sorting algorithm
str[j]=str[i];
str[i]=temp;
}
}
}
printf("%s\n",str);
getch();
return 0;
}
int main()
{
char s1[100],s2[100],temp;
int c=0;
clrscr();
printf("Enter the string 1:");
gets(s1);
printf(“enter the string 2”)
gets(s2);
count1++;
c++;
c=0;
count2++;
c++;
}
if(count1>count2)
printf(“string 1”);
Else
printf(“string 2”);
Return 0;
#include<stdio.h>
#include<stdlib.h>
#define MAX 256
return count_char;
}
int main()
{
char str1[100],str2[100];
int n=CountCommonChar(str1,str2);
printf("Common char = %d",n);
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
char string[1000];
gets(string);
printf("The string in upper case: %s\n", strupr(string));
return 0;