C Programs
C Programs
functions
#include<stdio.h>
int main()
{
int a,b,choice;
int sum,sub,mul;
float div;
printf("Enter the values of a & b: ");
scanf("%d %d",&a,&b);
printf("enter 1 for addition\n”);
printf("enter 2 for subtraction\n”);
printf("enter 3 for division\n”);
printf("enter 4 for multiplication\n”);
printf("Enter your Choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1 :
sum=a+b;
printf(“the sum is %d",sum);
break;
case 2 :
sub=a-b;
printf(“the difference is %d",sub”);
break;
case 3 :
div=a/b;
printf(“the quotient is %f",div);
break;
case 4 :
mul=a*b;
printf(“the multiplication is %d",mul);
break;
default :
printf(" Enter Correct Choice(1-4)");
break;
}
return 0;
}
int main()
{
int A = 10, B = 22, C = 9;
printf("The numbers A, B and C are: %d, %d, %d\n", A,
B,C);
if (A >= B)
{
if (A >= C)
printf("%d is the largest number.", A);
else
printf("%d is the largest number.", C);
}
else {
if (B >= C)
printf("%d is the largest number.", B);
else
printf("%d is the largest number.", C);
}
return 0;
#include <stdio.h>
int main()
{
int integerType;
char charType;
float floatType;
double doubleType;
return 0;
}
printf("\n");
i++;
}
Return 0;
}
// Driver code
int main()
{
return 0;
}
#include<stdio.h>
int main()
char c;
printf(“enter an alphabet”);
scanf(“%c”, &c);
if (lowercase_vowel || uppercase_vowel)
else
return 0;
*/
#include <stdio.h>
main() {
// C program to implement
// the getchar() function unformatted function
#include <conio.h>
#include <stdio.h>
// Driver code
int main()
{
// Declaring a char type variable
char ch;
printf("Enter the character: ");
// Taking a character from keyboard
ch = getchar();
// Displays the value of ch
printf("%c", ch);
return 0;
}
// C program to implement
// the getchar & putchar() function
#include <conio.h>
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
// Reads a character
ch = getchar();
// Displays that character
putchar(ch);
return 0;
}
// C program to implement
// the gets() & puts() function
#include <stdio.h> //
int main()
{
char name[50];
printf("Enter your text:\n ");
// Reads string from user
gets(name);
printf("Your text is:\n ");
// Displays string
puts(name);
return 0;
}
// C program to implement
// getch() function
#include <conio.h>
#include <stdio.h>
// Driver code
int main()
{
printf("Enter any character: ");
return 0;
}
// C program to implement
// the putch() functions
#include <conio.h>
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character:\n ");
// Reads a character from the keyboard
ch = getch();
printf("\nEntered character is: ");
// Displays that character on the console
putch(ch);
return 0;
}
// C program to implement
// the getche() function
#include <conio.h>
#include <stdio.h>
// Driver code
int main()
{
printf("Enter any character: ");
// Reads a character and
// displays immediately
getche();
return 0;
}
#include<stdio.h>
int add(int m, int n); //function declaration
int sub(int x, int y);
int div(int p, int q);
int mul(int a, int b);
main()
{
int a, b, sum, sub1,div1,mul1;
printf(“enter the value of a and b\n”);
scanf(“%d%d”, &a,&b);
sum=add(a,b); // calling of sub function
sub1=sub(a,b);
div1=div(a,b);
mul1=mul(a,b);
printf(“the sum is %d\n”, sum);
printf(“the difference is%d\n”, sub1);
printf(“the division output is%d\n”,div1);
printf(“the multiply output is %d\n”,mul1);
}
int add(int m, int n) //function definition
{
int sum1;
sum1=m+n;
return(sum1);
}
int sub(int x, int y)
{
Int sub1;
sub1=x-y;
return(sub1);
}
int div(int p, int q)
{
float div1;
div1=p/q;
return(div1);
}
int mul(int a, int b)
{
int mul1;
mul1=a*b;
return(mul1);
}
// c program to calculate factorial of number using functions
// C program to Find the Factorial Using for Loop
#include <stdio.h>
int factorial(int n)
{
int fact = 1, i;//local variables
// Loop from 1 to N to get the factorial
for (i = 1; i <= n; i++) //executable statements
{
//fact *= i;
fact=fact*i;
}
return fact;
}
int main()
{
int n, fact;
printf(“enter the number\n”);
scanf(“%d”, &n);
fact = factorial(n);// FUNCTION CALLING
printf("Factorial of %d is %d", n, fact);
return 0;
}
int main()
{
return 0;
}
int main()
{
// array declaration and initialization
int arr[5] = { 10, 20, 30, 40, 50 };
return 0;
}
int main() {
scanf("%d", &r);
scanf("%d", &c);
scanf("%d", &a[i][j]);
scanf("%d", &b[i][j]);
if (j == c - 1) {
printf("\n\n");
return 0; }
int main()
{
char dest[50] = "This is an";
char src[50] = " example";
return 0;
}
strlwr() strupr()
// a program to use strncpy()
#include<stdio.h>
#include<string.h>
int main()
{
char first[100] = "I am studying in PCTE";
char second[100] = "and I am a student of BCA IB";
printf("String s1 before is: %s \n", first);
int main()
{
int num;
printf("Enter the number\n");
scanf("%d",&num);
int count=0;
for(int i=2;i<=sqrt(num);i++) //Iterate from 2 to sqrt(num)
{
if(num%i==0)
{
count++;
break;
}
}
if(count!=0) //Check whether prime or not
{
printf("Not a prime number\n");
}
else
{
printf("Prime number\n");
}
return 0;
}
int main()
int a, b, c;
return 0;
// function definition
return x;
else
if(y > z)
return y;
else
return z;
struct student
{
char sname[20];
char class[10];
int age;
} struct student std1;
int main()
{
//struct student std1;
int main()
{
int i;
printf("Enter information of students:\n");
// storing information
for (i = 0; i < 5; ++i)
{
s[i].roll = i + 1;
printf("\nFor roll number%d,\n", s[i].roll);
printf("Enter first name: ");
scanf("%s", s[i].firstName);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("Displaying Information:\n\n");
// displaying information
for (i = 0; i < 5; ++i) {
printf("\nRoll number: %d\n", i + 1);
printf("First name: ");
puts(s[i].firstName);
printf("Marks: %.1f", s[i].marks);
printf("\n");
}
return 0;
}
int main()
{
s1.roll_no = 27;
strcpy(s1.name, "Kamlesh Joshi");
strcpy(s1.branch, "Computer Science And Engineering");
s1.batch = 2019;
printf("Roll Number: %d\n", (*ptr).roll_no);
printf("Name: %s\n", (*ptr).name);
printf("Branch: %s\n", (*ptr).branch);
printf("Batch: %d", (*ptr).batch);
return 0;
}