Priyanka C Program 11
Priyanka C Program 11
Output :
} if(num2!=0)
{
printf("Remainder:%d\n",num1%num2);
} else
{
printf("cannot calculate remainder when dividing by zero.\n");
} return
0;
}
Output :
1.
2.
switch (choice)
{
case 1:
printf("Hello! Welcome to the world of c programming\n");
break;
case 2:
printf("Enter a value: "); scanf("%d",&n);
if (n% 2 ==0)
{
printf("The number is even\n");
}else
{
printf("The number is odd\n");
}
break;
case 3:
printf("Enter the value: "); scanf("%d",&a);
if(a>=0)
{
printf("The value is +ve\n");
}
else
{
printf("The value is -ve\n");
}
break;
case 4:
printf("Enter a character: ");
scanf(" %c", &ch); //Added a space before %c to consume any whitespace
if (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||
ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
{
printf("The character is a vowel\n");
}
else {
printf("The character is a consonant\n");
}
break;
default:
printf("Invalid choice\n");
break;
}
return 0;
}
Output :
printf("%d+%d=%d",Num1,Num2,Num1+Num2);
break;
case '-':
printf("%d-%d=%d",Num1,Num2,Num1-Num2);
break; case '*':
printf("%d*%d=%d",Num1,Num2,Num1*Num2);
break;
case '/':
printf("%d/%d=%f",Num1,Num2,(float)Num1/Num2);
break;
default:
printf("Error! Invalid operator");
break;
} return
0;
}
Output :
1.
2.
3.
4.
5.
int main() {
int user_value; printf("Enter a
positive integer: ");
scanf("%d",&user_value);
}
for (int i= 1; i<=user_value; i++
{
if(i % 2 == 0)
{
continue;
}
factorial_continue *=i;
}
printf("\nFactorial using while loop: %d\n", factorial_while);
printf("\nFactorial using do-while loop: %d\n", factorial_do_while);
printf("\nFactorial using for loop: %d\n", factorial_for);
printf("\nFactorial using break statement: %d\n", factorial_break);
printf("\nFactorial using continue statement: %d\n",
factorial_continue);
return 0;
Output:
Output :
Output :
1.
2.
Output :
}
}
printf("enter the second matrix element=\n");
for(i=0;i<r;i++) {
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("multiply of the matrix=\n");
for(i=0;i<r;i++) {
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
//for printing result
for(i=0;i<r;i++) {
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
} return
0;
}
Output :
Output :
Output :
return 0;
}
Output :
#include <stdio.h>
void swapNumbers(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int num1, num2;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("\nOriginal Numbers:\n");
printf("First number: %d\n", num1);
printf("Second number: %d\n", num2);
swapNumbers(&num1, &num2);
printf("\nAfter Swapping:\n");
printf("First number: %d\n", num1);
printf("Second number: %d\n", num2);
return 0;
}
Output:
if (file != NULL)
{
fprintf(file, "Hello, this is a sample file.");
fclose(file);
printf("File created successfully!\n");
}
else
{
printf("Error in creating the file.\n");
}
}
void readFile()
{
FILE *file = fopen("sample.txt", "r");
char buffer[100];
if (file != NULL)
{
while (fgets(buffer, sizeof(buffer), file) != NULL)
{
printf("%s", buffer);
}
fclose(file);
}
else {
printf("Error in reading the file.\n");
}
}
void updateFile()
{
FILE *file = fopen("sample.txt", "a");
if (file != NULL)
{
fprintf(file, "\nUpdated content.");
fclose(file);
printf("File updated successfully!\n");
}
else {
printf("Error in updating the file.\n");
}
}
void deleteFile()
{
if (remove("sample.txt") == 0)
{
printf("File deleted successfully!\n");
}
else {
printf("Error in deleting the file.\n");
}
} int
main() {
createFile();
printf("\nFile Contents:\n");
readFile(); updateFile();
printf("\nUpdated File Contents:\n");
readFile();
deleteFile(); return
0;
}
Output :