C Language Standard Questions
C Language Standard Questions
#include <stdio.h>
int main()
{
int n, i;
printf("Enter a number: ");
scanf("%d", &n);
printf("Multiplication table of %d:\n ", n);
return 0;
}
#include <stdio.h>
void main() {
int i, n, sum = 0;
}
#include <stdio.h>
void main() {
int i, j, rows, k = 1;
printf("\n");
}
}
#include <stdio.h>
int main()
{
int arr1[100];
int i, mx, mn, n;
mx = arr1[0];
mn = arr1[0];
return 0;
}
#include <stdio.h>
int main()
{
int i, j, a, n, number[30]={9,8,7,6,5,4,3,2,1};
n=9;
}
#include <stdio.h>
int main() {
int arr1[3][3], i, j;
return 0;
}
#include <stdio.h>
int main()
{
int i;
int data[5];
return 0;
}
#include <stdio.h>
int main()
{
char str[100], * ptr;
int count;
printf("Enter any string: ");
gets(str);
ptr = str;
count = 0;
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main() {
int i,n;
int *data;
printf("Enter the total number of elements: ");
scanf("%d", &n);
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b);
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b);
return 0;
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b);
}
#include <stdio.h>
int main()
{
char str[150];
char *p;
int vCnt=0,cCnt=0;
p=str;
while(*p!='\0')
{
if(*p=='A' ||*p=='E' ||*p=='I' ||*p=='O' ||*p=='U'
||*p=='a' ||*p=='e' ||*p=='i' ||*p=='o' ||*p=='u')
vCnt++; //vowel count
else
cCnt++; //consonant count
p++;
}
struct book{
char title[10];
double price;
int pages;
};
int main(){
return 0;
}
#include <stdio.h>
int main() {
char str1[50];
char revstr[50];
char *stptr = str1;
char *rvptr = revstr;
int i = -1;
while (i >= 0) {
stptr--;
*rvptr = *stptr;
rvptr++;
--i;
}
*rvptr = '\0';
return 0;
}
#include <stdio.h>
int fact(int);
void main()
{
int sum;
sum=fact(1)/1 + fact(2)/2 + fact(3)/3 + fact(4)/4 + fact(5)/5;
int fact(int n)
{
int num=0,f=1;
while(num<=n-1)
{
f = f+f*num;
num++;
}
return f;
}
#include <stdio.h>
void decToBinary(int n)
{
int binaryNum[32]; int main()
{
int i = 0; int n = 17;
int j; decToBinary(n);
while (n > 0) {
// storing remainder in binary array return 0;
binaryNum[i] = n % 2; }
n = n / 2;
i++;
}
int main()
{
int n1;
printf(" Input any number: ");
scanf("%d", &n1);
if(checkArmstrong(n1))
{
printf(" The %d is an Armstrong number.\n", n1);
}
else
{
printf(" The %d is not an Armstrong number.\n", n1);
}
if(checkPerfect(n1))
{
printf(" The %d is a Perfect number.\n\n", n1);
}
else
{
printf(" The %d is not a Perfect number.\n\n", n1);
}
return 0;
}
// Checks whether a three digits number is Armstrong number or not.
//An Armstrong number is an n-digit number that is equal
//to the sum of the n-th powers of its digits.
int checkArmstrong(int n1)
{
int ld, sum, num;
sum = 0;
num = n1; // Checks whether the number is perfect number or not.
while(num!=0) //a perfect number is a positive integer that is equal to
{ //the sum of its positive divisors excluding the number itself
ld = num % 10; int checkPerfect(int n1)
sum += ld * ld * ld; {
num = num/10; int i, sum, num;
} sum = 0;
return (n1 == sum); num = n1;
} for(i=1; i<num; i++)
{
if(num%i == 0)
{
sum += i;
}
}
return (n1 == sum);
}
#include <stdio.h>
int main()
{
int arr[] = { 10, 324, 45, 90, 9808 };
int n = sizeof(arr) / sizeof(arr[0]);
int main()
{
char str[100];
int l=0;
return 0;
}
#include <stdio.h>
#include <string.h>
void main()
{
char s[200];
int count = 0, i;
if (fptr == NULL)
{
printf("File does not exists \n");
return;
}
printf("Enter the name \n");
scanf("%s", name);
fprintf(fptr, "Name = %s\n", name);
printf("Enter the age\n");
scanf("%d", &age);
fprintf(fptr, "Age = %d\n", age);
fclose(fptr);
}
#include <stdio.h>
int main()
{
FILE *fileptr;
int count_lines = 0;
char filechar[40], chr;
chr = getc(fileptr);
}
fclose(fileptr);
printf("There are %d lines in %s in a file\n", count_lines, filechar);
return 0;
}
#include <stdio.h>
#include <string.h>
int main()
{
FILE* ptr;
char ch;
if (NULL == ptr) {
printf("file can't be opened \n");
}
do {
ch = fgetc(ptr);
printf("%c", ch);
fclose(ptr);
return 0;
}
Thank You!!